Skip to content

Commit

Permalink
house keeping (#6)
Browse files Browse the repository at this point in the history
* 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
BrandonMFong authored Oct 30, 2024
1 parent f90fd87 commit 7547c2b
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 115 deletions.
2 changes: 1 addition & 1 deletion external/libs
Submodule libs updated 64 files
+34 −2 bflibc/makefile
+1 −0 bflibc/src/bflibc.h
+1 −0 bflibc/src/bftests.h
+1 −0 bflibc/src/bftime.c
+2 −0 bflibc/src/bftime.h
+24 −14 bflibc/src/coreutils.c
+11 −5 bflibc/src/coreutils.h
+60 −44 bflibc/src/lock.c
+9 −8 bflibc/src/lock.h
+43 −0 bflibc/src/stringutils.c
+15 −0 bflibc/src/stringutils.h
+12 −14 bflibc/src/thread.c
+29 −12 bflibc/testbench/coreutils_tests.h
+29 −0 bflibc/testbench/filesystem_tests.h
+12 −6 bflibc/testbench/lock_tests.h
+94 −0 bflibc/testbench/stringutils_tests.h
+1 −1 bflibc/testbench/tests.c
+42 −5 bflibcpp/makefile
+21 −11 bflibcpp/src/array.hpp
+18 −10 bflibcpp/src/atomic.hpp
+3 −0 bflibcpp/src/bflibcpp.hpp
+14 −0 bflibcpp/src/bftests.hpp
+69 −61 bflibcpp/src/bintree.hpp
+87 −0 bflibcpp/src/data.cpp
+107 −0 bflibcpp/src/data.hpp
+4 −4 bflibcpp/src/dictionary.hpp
+42 −7 bflibcpp/src/list.hpp
+1 −5 bflibcpp/src/path.cpp
+14 −10 bflibcpp/src/rbtree.hpp
+54 −3 bflibcpp/src/string.cpp
+33 −4 bflibcpp/src/string.hpp
+3 −3 bflibcpp/src/time.hpp
+59 −16 bflibcpp/testbench/atomic_tests.hpp
+40 −36 bflibcpp/testbench/bintree_tests.hpp
+4 −6 bflibcpp/testbench/cpplib_tests.hpp
+332 −0 bflibcpp/testbench/data_tests.hpp
+42 −1 bflibcpp/testbench/list_tests.hpp
+44 −43 bflibcpp/testbench/rbtree_tests.hpp
+120 −0 bflibcpp/testbench/string_tests.hpp
+3 −1 bflibcpp/testbench/tests.cpp
+154 −0 bfnet/makefile
+20 −0 bfnet/src/bfnet.hpp
+29 −0 bfnet/src/buffer.cpp
+34 −0 bfnet/src/buffer.hpp
+102 −0 bfnet/src/client.cpp
+36 −0 bfnet/src/client.hpp
+132 −0 bfnet/src/connection.cpp
+96 −0 bfnet/src/connection.hpp
+30 −0 bfnet/src/envelope.cpp
+35 −0 bfnet/src/envelope.hpp
+30 −0 bfnet/src/internal/log.hpp
+38 −0 bfnet/src/log.cpp
+27 −0 bfnet/src/log.hpp
+142 −0 bfnet/src/server.cpp
+52 −0 bfnet/src/server.hpp
+218 −0 bfnet/src/socket.cpp
+158 −0 bfnet/src/socket.hpp
+12 −0 bfnet/testbench/bfnet_tests.hpp
+246 −0 bfnet/testbench/socket_tests.hpp
+31 −0 bfnet/testbench/tests.cpp
+3 −0 makefile
+7 −4 makefiles/libpaths.mk
+7 −6 readme.md
+5 −0 scripts/runtests
87 changes: 50 additions & 37 deletions scripts/gotoutils.sh
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;
}
6 changes: 5 additions & 1 deletion scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ function main() {
exit $?;
else
printf "Installation complete\n";
printf "Please add \`source ~/.gotoutils/gotoutils.sh\` in your shell profile\n";
if [ -n $ZSH_VERSION ]; then
printf "Please add \`source ~/.gotoutils/gotoutils.sh; goto_init_zsh;\` in your shell profile\n";
else
printf "Please add \`source ~/.gotoutils/gotoutils.sh; goto_init_bash;\` in your shell profile\n";
fi
fi
fi

Expand Down
Loading

0 comments on commit 7547c2b

Please sign in to comment.