dev-env/dev-env.sh
2025-01-29 16:55:33 +00:00

87 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
_notes_locations_print()
{
echo "\t\ttodo.txt:\t$TODOTXTPATH"
echo "\t\twiki:\t\t$VIMWIKIPATH"
echo "\t\tvimrc\t\t$MYVIMRC"
}
_help()
{
echo "dev-env.sh usage: $0 [mode]"
echo "\txn: Extract notes to:"
_notes_locations_print
echo "\tsn: Store notes:"
_notes_locations_print
echo "\ttmux: Launch standard tmux session."
exit 1
}
_extract_notes()
{
if [ ! -e "./archive.tar.gz" ];
then
echo "archive.tar.gz does not exist."
exit 1
fi
mkdir tmp
tar xzf archive.tar.gz -C .
cp -r ./tmp/wiki $(dirname $VIMWIKIPATH)
cp ./tmp/todo.txt $TODOTXTPATH
cp ./tmp/.vimrc $MYVIMRC
rm -r ./tmp
echo "Notes successfully extracted from archive."
exit 0
}
_storage_notes()
{
mkdir tmp
cp $TODOTXTPATH ./tmp/
cp -r $VIMWIKIPATH ./tmp/
cp $MYVIMRC ./tmp/
tar czf archive.tar.gz ./tmp/
rm -r tmp
echo "Notes successfully stored!"
exit 0
}
_launch_tmux()
{
tmux new-session -d 'vim $TODOTXTPATH $VIMWIKIPATH/index.md'
tmux new-window 'bash'
tmux -2 attach-session -d
}
# main
# check for the neccessary variables
if [ -z "$VIMWIKIPATH" ];
then
echo "VIMWIKIPATH not set."
exit 1
fi
if [ -z "$TODOTXTPATH" ];
then
echo "TODOTXTPATH not set."
exit 1
fi
if [ -z "$MYVIMRC" ];
then
echo "MYVIMRC not set."
exit 1
fi
# run the user's command
case "$1" in
sn ) _storage_notes ;;
xn ) _extract_notes ;;
tmux ) _launch_tmux ;;
* ) _help ;;
esac