From 0860036eff5e5fa42186260734b6dce1c2448885 Mon Sep 17 00:00:00 2001 From: bretello Date: Sat, 7 Dec 2019 22:32:14 +0100 Subject: [PATCH] fix some miscellanous issues --- aliases.sh | 2 +- brethil_dotfile.sh | 10 ++++---- functions.sh | 60 +++++++++++++++++++++++----------------------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/aliases.sh b/aliases.sh index d013cc2..b9c05ce 100755 --- a/aliases.sh +++ b/aliases.sh @@ -82,5 +82,5 @@ fi # dotfiles user aliases if [[ -f ~/.dotfiles_aliases ]]; then - source ~/.dotfiles_aliases + source $HOME/.dotfiles_aliases fi diff --git a/brethil_dotfile.sh b/brethil_dotfile.sh index 5815de1..08742e9 100755 --- a/brethil_dotfile.sh +++ b/brethil_dotfile.sh @@ -58,12 +58,12 @@ if [[ $SSH_CLIENT ]]; then fi -alias esource="$EDITOR $HOME/.zshrc" -alias resource="source $HOME/.zshrc" -alias dotedit="$EDITOR $DOTFILES/brethil_dotfile.sh" +alias esource='$EDITOR $HOME/.zshrc' +alias resource='source $HOME/.zshrc' +alias dotedit='$EDITOR $DOTFILES/brethil_dotfile.sh' # Custom definitions files -alias funedit="$EDITOR ~/.dotfiles_functions.sh" -alias aledit="$EDITOR ~/.dotfiles_aliases.sh" +alias funedit='$EDITOR ~/.dotfiles_functions.sh' +alias aledit='$EDITOR ~/.dotfiles_aliases.sh' # Extras functions_file=$DOTFILES/functions.sh # Function definitions diff --git a/functions.sh b/functions.sh index d6584fe..5ff4606 100755 --- a/functions.sh +++ b/functions.sh @@ -21,7 +21,7 @@ function cheatall # List all docker tags for an image function dockertags { - if [[ -z `which jq` ]]; then + if [[ -z $(command -v jq) ]]; then echo "jq not installed. Please install jq." 1>&2 return fi @@ -35,28 +35,30 @@ function dockertags ## Simple calculator. Usage: calc 1+1, calc 5/7, calc "sqrt(2)" function calc { - awk "BEGIN { print "$*" }" + awk "BEGIN { print $* }" } ## Make new directory and cd to that directory. Usage: mcd newfolder function mcd { - mkdir -p $1 + mkdir -p "$1" cd $1 } ## Print full path of item in current directory function ppath { - echo $PWD/"$1" + echo "$PWD/$1" } -## Color string with given color. Usage: color colorname "string", available colors in colors.sh +## Color string with given color. Usage: color $colorname "string", available colors in colors.sh function color { color=$1 + set -x shift 1 - printf "$color$@$CLEAR" + echo -e "$"$color"$@${CLEAR}\n" + set +x } @@ -100,17 +102,19 @@ function pmusic ## Simple http server for current directory (or path) function httpserver { - cwd="$pwd" - if [[ -e $1 ]]; - then - dir="$1" - else - dir="$pwd" - fi - cd "$dir" - sleep 0.1 && open "http://localhost:8000" &>/dev/null & - python -m SimpleHTTPServer - + ( + if [[ -d $1 ]]; then + cd "$1" && echo "Starting webserver in $(realpath $1)/" || echo "directory: $1 does not exist" >&2 || exit 1 + else + echo "Starting webserver in $PWD/" + fi + open "http://localhost:8000" &>/dev/null & + if [[ $(python --version) == "Python 3"* ]]; then + python -m http.server 8000 + else + python -m SimpleHTTPServer + fi + ) } @@ -169,7 +173,7 @@ fi ## List defined functions in $DOTFILES/functions.sh function list_functions { - cat $DOTFILES/functions.sh | grep --color=no -A 1 '^##' | sed -E 's/function (.*)/\1/g' + grep --color=no -A 1 '^##' $DOTFILES/functions.sh | sed -E 's/function (.*)/\1/g' } @@ -194,9 +198,9 @@ function ramdisk mydev=$(hdiutil attach -nomount ram://$NUMSECTORS ) # strip whitespace (hdiutil outputs a lot of spaces/tabs along with the device name) mydev=$(echo "$mydev"| xargs echo) - newfs_hfs $mydev + newfs_hfs "$mydev" mkdir -p "/tmp/$name" - mount -t hfs $mydev "/tmp/$name" + mount -t hfs "$mydev" "/tmp/$name" echo "RAM Disk mounted: /tmp/$name" echo "To eject (destroy) RAM disk, use:" echo " $ diskutil eject $mydev" @@ -212,18 +216,14 @@ function man2pdf function nman { if [ $# -eq 1 ] ; then - open x-man-page://$1 ; + open "x-man-page://$1" elif [ $# -eq 2 ] ; then - open x-man-page://$1/$2 ; + open "x-man-page://$1/$2" fi } -fi # end of mac-specific functions +fi -# Force update git repo from origin/master -function gitupdate(){ - git fetch --all - git reset --hard origin/master -} +### end of mac-specific functions function pipupdate(){ for pip in pip2 pip3; do @@ -235,6 +235,6 @@ function pipupdate(){ } # dotfiles user functions -if [[ -f ~/.dotfiles_functions ]]; then - source ~/.dotfiles_functions +if [[ -f $HOME/.dotfiles_functions ]]; then + source "$HOME/.dotfiles_functions" fi