-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixes error handling in rust as I am still learning the language * removes all goto-* functions and relies on the underlying tool to do that argument handling. This reduces the amount of scripting needed
- Loading branch information
1 parent
f90fd87
commit 7547c2b
Showing
5 changed files
with
168 additions
and
115 deletions.
There are no files selected for viewing
Submodule libs
updated
64 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,75 @@ | ||
#!/bin/bash | ||
|
||
|
||
GOTO_UTILS_DATA_DIR=~/.gotoutils | ||
GOTO_UTILS_TOOL=$GOTO_UTILS_DATA_DIR/gototool | ||
|
||
# gets path from keypaths file using key pair then cds to it | ||
function goto() { | ||
p=$($GOTO_UTILS_TOOL getpath $1); | ||
error=$?; | ||
if [ $error -eq 0 ]; then | ||
cd $p; | ||
GOTO_UTILS_TOOL_ACCEPTED_ARGS=("$($GOTO_UTILS_TOOL --accepted-args)"); | ||
|
||
function emulate_goto() { | ||
type emulate > /dev/null 2>&1; | ||
if [ $? -eq 0 ]; then | ||
emulate $@; | ||
fi | ||
} | ||
|
||
# cds into the last previous path used in goto() | ||
function goto-prev() { | ||
p=$($GOTO_UTILS_TOOL getpath-prev); | ||
function goto() { | ||
old=$(emulate_goto); | ||
emulate_goto bash; | ||
cont=true; | ||
p=$($GOTO_UTILS_TOOL $@); | ||
error=$?; | ||
if [ $error -eq 0 ]; then | ||
if [ $error -ne 0 ]; then | ||
cont=false; | ||
fi | ||
|
||
# should default to show help | ||
if [ $cont == true ]; then | ||
len=$#; | ||
if [ $len -eq 0 ]; then | ||
cont=false; | ||
fi | ||
fi | ||
|
||
# seeing if the user passed an argument for the tool as opposed | ||
# to a key for a path | ||
# | ||
# we are also looking out for `--prev`, as the tool will | ||
# return the previous directory we were in. Then we will cd | ||
# into that directory | ||
if [ $cont == true ]; then | ||
for arg in ${GOTO_UTILS_TOOL_ACCEPTED_ARGS[@]}; | ||
do | ||
if [ "$arg" == "$1" ] && [ "$arg" != "--prev" ]; then | ||
cont=false; | ||
fi | ||
done | ||
fi | ||
|
||
if [ $cont == true ]; then | ||
cd $p; | ||
else | ||
__goto-print-error "history empty"; | ||
if [ ${#p} -gt 0 ]; then | ||
printf "$p\n"; | ||
fi | ||
fi | ||
|
||
|
||
emulate_goto $old; | ||
return $error; | ||
} | ||
|
||
# https://keyholesoftware.com/2022/07/18/adding-autocompletion-to-bash-scripts/ | ||
function __goto_completion() { | ||
if [ $COMP_CWORD -eq 1 ]; then | ||
cur=${COMP_WORDS[COMP_CWORD]} | ||
COMPREPLY=( $(./bin/release/gototool getsugkeys $cur) ) | ||
fi | ||
} | ||
complete -F __goto_completion goto | ||
|
||
function goto-add() { | ||
if [ $# -ne 2 ]; then | ||
__goto-print-error "goto-add <key> <path>"; | ||
else | ||
$GOTO_UTILS_TOOL add $1 $2; | ||
COMPREPLY=( $($GOTO_UTILS_TOOL --show-suggested-keys $cur) ) | ||
fi | ||
} | ||
|
||
function goto-remove() { | ||
$GOTO_UTILS_TOOL rm $1; | ||
function goto_init_bash() { | ||
complete -F __goto_completion goto | ||
} | ||
|
||
function goto-showkeys() { | ||
$GOTO_UTILS_TOOL getkeys $1; | ||
function goto_init_zsh() { | ||
} | ||
|
||
function __goto-print-error() { | ||
echo "goto: $@" 1>&2; | ||
} | ||
|
||
function goto-showall() { | ||
$GOTO_UTILS_TOOL getallpairs; | ||
} | ||
|
||
function goto-version() { | ||
$GOTO_UTILS_TOOL version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.