Trying to clean some things up
This commit is contained in:
parent
439cd48963
commit
2aa979cf0e
2 changed files with 13 additions and 12 deletions
5
_goto
5
_goto
|
@ -1,7 +1,8 @@
|
||||||
|
#!/usr/bin/zsh
|
||||||
function _goto {
|
function _goto {
|
||||||
for label in $(_awk '{print $1}' `_gotofile`)
|
for label in $(_awk '{print $1;}' `_goto_file`)
|
||||||
do
|
do
|
||||||
compadd "$@" $label
|
compadd "$@" "${label}"
|
||||||
done
|
done
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,21 +7,21 @@ function _awk {
|
||||||
which gawk &>/dev/null && gawk $@
|
which gawk &>/dev/null && gawk $@
|
||||||
};
|
};
|
||||||
|
|
||||||
function _gotofile {
|
function _goto_file {
|
||||||
echo "${GOTO_FILE:-${HOME/.labels.tsv}}"
|
echo "${GOTO_FILE:-${HOME}/.labels.tsv}"
|
||||||
};
|
};
|
||||||
|
|
||||||
function _make_label {
|
function _make_label {
|
||||||
printf '%s %s\n' "$1" $(echo "$2" | tr -d "$HOME/") >> `_gotofile`
|
printf '%s %s\n' "$1" $(echo "$2" | tr -d "$HOME/") >> `_goto_file`
|
||||||
};
|
};
|
||||||
|
|
||||||
function label {
|
function label {
|
||||||
if [ "${#}" -eq 0 ]; then
|
if [[ "${#}" -eq 0 ]]; then
|
||||||
echo "Usage: $ label <name> [dir]"
|
echo "Usage: $ label <name> [dir]"
|
||||||
echo " creates a label which goto can cd to"
|
echo " creates a label which goto can cd to"
|
||||||
elif [ -d "${2}" ]; then
|
elif [[ -d "${2}" ]]; then
|
||||||
_make_label "${1}" "${2}"
|
_make_label "${1}" "${2}"
|
||||||
else
|
elsep
|
||||||
_make_label "${1}" "${PWD}"
|
_make_label "${1}" "${PWD}"
|
||||||
fi
|
fi
|
||||||
};
|
};
|
||||||
|
@ -31,14 +31,14 @@ function goto {
|
||||||
echo "Usage: $ goto <name>"
|
echo "Usage: $ goto <name>"
|
||||||
echo " jumps to a record set by label"
|
echo " jumps to a record set by label"
|
||||||
elif [[ "$1" == "ls" ]]; then
|
elif [[ "$1" == "ls" ]]; then
|
||||||
_awk "{ print \$1 }" `_gotofile` | column -t
|
_awk '{print $1;}' `_goto_file` | column -t
|
||||||
else
|
else
|
||||||
dir=$(_awk "/^$1\s/ {print \$2;exit;}" `_gotofile` | head -n 1)
|
dir=$(_awk "/^$1\s/ {print \$2;exit;}" `_goto_file` | head -n 1)
|
||||||
if [[ "${dir}" != "/*" ]]; then
|
if [[ "${dir}" != "/*" ]]; then
|
||||||
dir="${HOME}/${dir}"
|
dir="${HOME}/${dir}"
|
||||||
fi
|
fi
|
||||||
if [[ ! -e "${dir}" ]]; then
|
if [[ ! -e "${dir}" ]]; then
|
||||||
echo "Error: Label '$1' resolved to missing path '$dir'"
|
echo "Error: Label '$1' resolved to missing path '$dir'"
|
||||||
else
|
else
|
||||||
cd "${dir}"
|
cd "${dir}"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue