Compare commits
No commits in common. "6411c2ed1282d2581946213d67ea5317e3de7456" and "7210cf5d490e7ece1ae9662552ae3cdfa98253b0" have entirely different histories.
6411c2ed12
...
7210cf5d49
9 changed files with 57 additions and 121 deletions
|
@ -8,7 +8,7 @@ $ cd ~/doc/programming/web/arrdem.com
|
||||||
$ echo $PWD
|
$ echo $PWD
|
||||||
/home/reid/doc/programming/web/arrdem.com
|
/home/reid/doc/programming/web/arrdem.com
|
||||||
# that's long as hell... let's fix that
|
# that's long as hell... let's fix that
|
||||||
$ label add arrdem.com
|
$ label arrdem.com
|
||||||
$ cd
|
$ cd
|
||||||
$ echo $PWD
|
$ echo $PWD
|
||||||
/home/reid
|
/home/reid
|
||||||
|
@ -17,6 +17,8 @@ $ echo $PWD
|
||||||
/home/reid/doc/programming/web/arrdem.com
|
/home/reid/doc/programming/web/arrdem.com
|
||||||
```
|
```
|
||||||
|
|
||||||
This is a alpha script and could use some serious attention.
|
This is a relatively alpha script and could use some serious attention.
|
||||||
|
|
||||||
- the labels file (~/.labels.tsv) _must_ be tab separated
|
- no way to delete labels once you set them besides editing the labels file
|
||||||
|
- the labels file (~/.labels.tsv) _must_ be tab seperated
|
||||||
|
- the error messages on a missing label are useless
|
||||||
|
|
8
_awk
8
_awk
|
@ -1,8 +0,0 @@
|
||||||
#!/usr/bin/env zsh
|
|
||||||
if command -v gawk &>/dev/null; then
|
|
||||||
gawk "${@}"
|
|
||||||
elif command -v awk &>/dev/null; then
|
|
||||||
awk "${@}"
|
|
||||||
else
|
|
||||||
echo "Unable to find an awk!" >&2; return 1
|
|
||||||
fi
|
|
7
_goto
7
_goto
|
@ -1,7 +0,0 @@
|
||||||
#compdef _goto goto
|
|
||||||
function _goto {
|
|
||||||
for label in $(label ls)
|
|
||||||
do
|
|
||||||
compadd "$@" "${label}"
|
|
||||||
done
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
#!/usr/bin/env zsh
|
|
||||||
echo "${GOTO_FILE:-${HOME}/.labels.tsv}"
|
|
24
_label
24
_label
|
@ -1,24 +0,0 @@
|
||||||
#compdef _label label
|
|
||||||
_label() {
|
|
||||||
local line state
|
|
||||||
|
|
||||||
_arguments -C \
|
|
||||||
"1: :->cmds" \
|
|
||||||
"*::arg:->args"
|
|
||||||
case "$state" in
|
|
||||||
cmds)
|
|
||||||
_values "label command" \
|
|
||||||
"add[Create or overwrite a label.]" \
|
|
||||||
"ls[List existing labels.]" \
|
|
||||||
"get[Fetch the location of a label.]" \
|
|
||||||
"rm[Delete a label.]"
|
|
||||||
;;
|
|
||||||
args)
|
|
||||||
case "$line[1]" in
|
|
||||||
rm|get)
|
|
||||||
_goto # get the labels as completions
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# MacOS support - prefer GNU sed eg. from Homebrew to 'sed'
|
|
||||||
if command -v gsed &>/dev/null; then
|
|
||||||
gsed "$@"
|
|
||||||
elif command -v sed &>/dev/null; then
|
|
||||||
sed "$@"
|
|
||||||
else
|
|
||||||
echo "Unable to find a sed!" >&2; return 1
|
|
||||||
fi
|
|
19
goto
19
goto
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
: "${1:=--help}"
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
-h|--help|help)
|
|
||||||
cat <<EOF
|
|
||||||
Usage:
|
|
||||||
$ goto [label]
|
|
||||||
|
|
||||||
Change directory to a labeled location.
|
|
||||||
See label for label control operations
|
|
||||||
EOF
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
cd "$(label get "$1")"
|
|
||||||
;;
|
|
||||||
esac
|
|
|
@ -1,10 +1,55 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/zsh
|
||||||
# this is a stub, commands are elsewhere
|
#
|
||||||
|
# goto.zsh, a tool for bookmarking directories
|
||||||
|
|
||||||
ROOT="$(realpath $(dirname $0))"
|
function _awk {
|
||||||
|
which awk &>/dev/null && awk $@ || \
|
||||||
|
which gawk &>/dev/null && gawk $@
|
||||||
|
};
|
||||||
|
|
||||||
|
function _goto_file {
|
||||||
|
echo "${GOTO_FILE:-${HOME}/.labels.tsv}"
|
||||||
|
};
|
||||||
|
|
||||||
|
function _make_label {
|
||||||
|
printf '%s %s\n' "$1" $(echo "$2" | tr -d "$HOME/") >> `_goto_file`
|
||||||
|
};
|
||||||
|
|
||||||
|
function label {
|
||||||
|
if [[ "${#}" -eq 0 ]]; then
|
||||||
|
echo "Usage: $ label <name> [dir]"
|
||||||
|
echo " creates a label which goto can cd to"
|
||||||
|
elif [[ -d "${2}" ]]; then
|
||||||
|
_make_label "${1}" "${2}"
|
||||||
|
elsep
|
||||||
|
_make_label "${1}" "${PWD}"
|
||||||
|
fi
|
||||||
|
};
|
||||||
|
|
||||||
# Note that since we manipulate $cwd, goto HAS to be a function.
|
|
||||||
# So we use this shim to hit the right script.
|
|
||||||
function goto {
|
function goto {
|
||||||
. "$ROOT/goto"
|
if [[ "${#}" -eq 0 ]]; then
|
||||||
}
|
echo "Usage: $ goto <name>"
|
||||||
|
echo " jumps to a record set by label"
|
||||||
|
elif [[ "$1" == "ls" ]]; then
|
||||||
|
_awk '{print $1;}' `_goto_file` | column -t
|
||||||
|
else
|
||||||
|
dir=$(_awk "/^$1\s/ {print \$2;exit;}" `_goto_file` | head -n 1)
|
||||||
|
if [[ "${dir}" != "/*" ]]; then
|
||||||
|
dir="${HOME}/${dir}"
|
||||||
|
fi
|
||||||
|
if [[ ! -e "${dir}" ]]; then
|
||||||
|
echo "Error: Label '$1' resolved to missing path '$dir'"
|
||||||
|
else
|
||||||
|
cd "${dir}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
};
|
||||||
|
|
||||||
|
function _goto {
|
||||||
|
for label in $(awk '{print $1}' `_goto_file`)
|
||||||
|
do
|
||||||
|
compadd "$@" $label
|
||||||
|
done
|
||||||
|
};
|
||||||
|
|
||||||
|
compdef _goto goto
|
||||||
|
|
39
label
39
label
|
@ -1,39 +0,0 @@
|
||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
: "${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"
|
|
||||||
_zsh_goto_sed -i '/^$/d' "$(_goto_file)" # Remove empty lines
|
|
||||||
_zsh_goto_sed -i -e '$a\' "$(_goto_file)" # Fix potentially missing last newline
|
|
||||||
printf '%s %s\n' "${2}" $(realpath "${3:-$PWD}" | _zsh_goto_sed "s^${HOME}^~^g") >> "$(_goto_file)"
|
|
||||||
;;
|
|
||||||
|
|
||||||
get)
|
|
||||||
realpath "$(_awk "/^$2\s/ {print \$2;exit}" `_goto_file` | _zsh_goto_sed "s|^~|$HOME|")"
|
|
||||||
;;
|
|
||||||
|
|
||||||
rm)
|
|
||||||
_zsh_goto_sed -i "/$2/d" "$(_goto_file)"
|
|
||||||
;;
|
|
||||||
|
|
||||||
ls)
|
|
||||||
_awk '{print $1;}' "$(_goto_file)"
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "Unknown command: $@" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
Loading…
Reference in a new issue