2022-08-17 22:46:24 +00:00
|
|
|
#!/usr/bin/env zsh
|
2022-08-11 06:11:04 +00:00
|
|
|
|
|
|
|
: "${1:=--help}"
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
-h|--help|help)
|
|
|
|
cat <<EOF
|
|
|
|
Usage:
|
|
|
|
$ label [add | get | rm | ls]
|
|
|
|
|
|
|
|
Set, list or manipulate configured labeles.
|
|
|
|
Note: the words 'help' and 'ls' among others are reserved, and cannot be labeled.
|
|
|
|
EOF
|
|
|
|
;;
|
|
|
|
|
|
|
|
add)
|
|
|
|
label rm "$2"
|
2022-11-26 19:03:29 +00:00
|
|
|
_zsh_goto_sed -i '/^$/d' "$(_goto_file)" # Remove empty lines
|
|
|
|
_zsh_goto_sed -i -e '$a\' "$(_goto_file)" # Fix potentially missing last newline
|
2022-11-26 19:08:34 +00:00
|
|
|
printf '%s %s\n' "${2}" $(realpath "${3:-$PWD}" | _zsh_goto_sed "s^${HOME}^~^g") >> "$(_goto_file)"
|
2022-08-11 06:11:04 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
get)
|
2022-11-26 19:03:29 +00:00
|
|
|
realpath "$(_awk "/^$2\s/ {print \$2;exit}" `_goto_file` | _zsh_goto_sed "s|^~|$HOME|")"
|
2022-08-11 06:11:04 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
rm)
|
2022-11-26 19:03:29 +00:00
|
|
|
_zsh_goto_sed -i "/$2/d" "$(_goto_file)"
|
2022-08-11 06:11:04 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
ls)
|
2022-11-26 19:03:29 +00:00
|
|
|
_awk '{print $1;}' "$(_goto_file)"
|
2022-08-11 06:11:04 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "Unknown command: $@" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|