mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
Added public zet configuration
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# Creates a new `zet` inside the public `Zettlekasten` directory.
|
||||
|
||||
_cmd_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Early out if the directory is not found.
|
||||
! test -d "$ZETDIR" && echo "Can't find ${ZETDIR:-'Not Found in ENV'}" && exit 1
|
||||
|
||||
# Early out if `isosec` is not found.
|
||||
! _cmd_exists isosec && echo "isosec not found." && exit
|
||||
|
||||
# Create a new directory for this note.
|
||||
dir="$ZETDIR/$(isosec)"
|
||||
mkdir "$dir"
|
||||
|
||||
# Create the readme file with the title (if supplied)
|
||||
readme="$dir/README.md"
|
||||
title="$*"
|
||||
printf "# %s\n\n" "${title}" > "${readme}"
|
||||
|
||||
# Bail if the readme was not created.
|
||||
! test -r "$readme" && echo "README was not created properly." && exit 1
|
||||
|
||||
# Auto commit the new note.
|
||||
message="${title:-"Autocommit message"}"
|
||||
cd "$dir"
|
||||
git pull -q
|
||||
git add -A "$dir"
|
||||
git commit -m "$message"
|
||||
git push
|
||||
cd -
|
||||
|
||||
# Open the note.
|
||||
exec vi "${readme}"
|
||||
96
zet/setup
Executable file
96
zet/setup
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/bin/sh
|
||||
|
||||
config="${HOME}/.config"
|
||||
uninstall=1
|
||||
remove=1
|
||||
copy=1
|
||||
link=0
|
||||
|
||||
_usage() {
|
||||
printf "\n" >&2
|
||||
printf "Usage: setup [OPTIONS]\n" >&2
|
||||
printf "\n" >&2
|
||||
printf "Installs or Uninstalls zet configuration files.\n" >&2
|
||||
printf "\n" >&2
|
||||
printf "Options:\n" >&2
|
||||
printf "\t-c | --copy : Copy the configuration files, instead of creating symlinks.\n" >&2
|
||||
printf "\t-h | --help : Print usage information.\n" >&2
|
||||
printf "\t-l | --link : Create symlinks to the configuration files (Default).\n" >&2
|
||||
printf "\t-r | --remove : Removes the entire ~/.config/zet directory.\n" >&2
|
||||
printf "\t-u | --uninstall : Uninstalls configuration files.\n" >&2
|
||||
printf "\n" >&2
|
||||
printf "If called without the uninstall option then it will install the configuration files.\n" >&2
|
||||
printf "The copy and link options are ignored if called with the uninstall or remove option.\n" >&2
|
||||
printf "\n" >&2
|
||||
}
|
||||
|
||||
_parse_options() {
|
||||
arg=
|
||||
while ! test -z "$1"; do
|
||||
arg="$1"
|
||||
case $arg in
|
||||
-c | --copy)
|
||||
copy=0
|
||||
link=1
|
||||
shift;;
|
||||
-h | --help)
|
||||
_usage
|
||||
exit;;
|
||||
-l | --link)
|
||||
copy=1
|
||||
link=0
|
||||
shift;;
|
||||
-r | --remove)
|
||||
remove=0
|
||||
shift;;
|
||||
-u | --uninstall)
|
||||
uninstall=0
|
||||
shift;;
|
||||
*)
|
||||
echo "Unknown option $arg" >&2
|
||||
shift;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
_make_dirs() {
|
||||
if ! test -d "${config}"; then
|
||||
mkdir "${config}"
|
||||
fi
|
||||
}
|
||||
|
||||
_remove_zet() {
|
||||
echo "Removing zet directory..."
|
||||
test -d "${config}/zet" && rm -r "${config}/zet"
|
||||
}
|
||||
|
||||
_link_zet() {
|
||||
echo "Linking git configuration..."
|
||||
ln -sfv "${PWD}/zet" "${config}"
|
||||
}
|
||||
|
||||
_copy_zet() {
|
||||
echo "Copying zet configuration..."
|
||||
cp -r "${PWD}/zet" "${config}"
|
||||
}
|
||||
|
||||
_install() {
|
||||
_make_dirs
|
||||
|
||||
test "$copy" -eq 0 && _copy_zet && return "$?"
|
||||
test "$link" -eq 0 && _link_zet && return "$?"
|
||||
echo "Neither link or copy was passed, see --help for usage"
|
||||
exit 1
|
||||
}
|
||||
|
||||
#------------------------------- main -------------------------------
|
||||
main() {
|
||||
_parse_options "$@"
|
||||
|
||||
test "$remove" -eq 0 && _remove_zet && exit "$?"
|
||||
test "$uninstall" -eq 0 && _remove_zet && exit "$?"
|
||||
|
||||
_install && exit "$?"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
3
zet/zet/config.json
Normal file
3
zet/zet/config.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"zetDirectory" : "/Volumes/Bucket/Repos/github.com/m-housh/zets"
|
||||
}
|
||||
Reference in New Issue
Block a user