Skip to content

Instantly share code, notes, and snippets.

@ktnyt
Last active December 26, 2022 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktnyt/d96ac47aca771dc2db8b8d87a83af86b to your computer and use it in GitHub Desktop.
Save ktnyt/d96ac47aca771dc2db8b8d87a83af86b to your computer and use it in GitHub Desktop.
Directory teleportation.
#!/bin/zsh
function tp() {
help() {
echo "usage: tp [-h | --help] [<alias>] [<directory>]"
}
TP_CONFIG_PATH="${XDG_CONFIG_HOME:-$HOME/.config}/tp"
TP_CONFIG_FILE="${TP_CONFIG_PATH}/config.tsv"
if [ ! -d $TP_CONFIG_PATH ]
then
mkdir -p $TP_CONFIG_PATH
fi
if [ ! -f $TP_CONFIG_FILE ]
then
touch $TP_CONFIG_FILE
fi
for arg in $*
do
case $arg in
-h|--help)
help
return
;;
esac
done
case $# in
0)
cat $TP_CONFIG_FILE
return
;;
1)
cd $(cat $TP_CONFIG_FILE | awk -v key="$1" '$1 == key' | cut -f 2)
return
;;
2)
{ cat $TP_CONFIG_FILE | awk -v key="$1" '$1 != key'; echo "$1\t$2" } | sort > $TP_CONFIG_FILE
;;
*)
help
return
;;
esac
}
function _tp() {
_arguments '1: :($(cat $TP_CONFIG_FILE | cut -f 1))' '2: :_path_files'
}
compdef _tp tp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment