diff --git a/zclick/zclick b/zclick/zclick index 8870aa0..51c7c96 100755 --- a/zclick/zclick +++ b/zclick/zclick @@ -24,63 +24,31 @@ arg_i=20 block_time=100 -if [ -z "$FOLDER" ] -then +[ -z "$FOLDER" ] && { if [ -n "$XDG_DATA_HOME" ] then FOLDER="$XDG_DATA_HOME/zclick" else FOLDER="$HOME/.local/share/zclick" fi -fi +} while getopts ":hi:b:dt" opt; do case $opt in - h) - usage - exit 0 - ;; - i) - if ! [ "$OPTARG" -ge 0 ] 2>/dev/null - then - error "i argument has to be positive" - exit 2 - fi - arg_i=$OPTARG - ;; - b) - if ! [ "$OPTARG" -ge 1 ] 2>/dev/null - then - error "b argument has to be strictly positive" - exit 2 - fi - block_time=$OPTARG - ;; - d) - opt_d=y - ;; - t) - opt_t=y - ;; - \?) - echo "Uknown option: $OPTARG" - usage - exit 1 - ;; + h) usage && exit 0 ;; + i) [ "$OPTARG" -ge 0 ] 2>/dev/null || { error "i argument has to be positive" ; exit 2; } + arg_i=$OPTARG ;; + b) [ "$OPTARG" -ge 1 ] 2>/dev/null || { error "b argument has to be strictly positive" ; exit 2; } + block_time=$OPTARG ;; + d) opt_d=y ;; + t) opt_t=y ;; + \?) echo "Unknown option: $OPTARG" >&2 ; usage ; exit 1 ;; esac done shift $((OPTIND-1)) -if [ -n "$1" ] && ! [ "$1" -gt 0 ] 2>/dev/null -then - error "Click ID has to be a strictly positive integer" - exit 2 -fi -cid=$1 - - mkdir -p "$FOLDER" if [ -n "$opt_d" ] @@ -114,12 +82,9 @@ then else ## CONTROL - - if [ -z "$cid" ] - then - usage - exit - fi + [ $# -le 0 ] && usage && exit 1 + [ -n "$1" ] && ! [ "$1" -gt 0 ] 2>/dev/null && { error "Click ID has to be a strictly positive integer" ; exit 2; } + cid=$1 if [ -n "$opt_t" ] then diff --git a/zcsf/zcsf b/zcsf/zcsf index adffdea..169dc59 100755 --- a/zcsf/zcsf +++ b/zcsf/zcsf @@ -10,15 +10,13 @@ Operations: make : create Makefile main : create main source file ls : list source names - src : create source files + src : create source files. Can be abbrieviated to 's' rm : delete source files mv : rename source files clear : delete all sources, headers, and binaries import [name] : import source files from another destination export : export source files to another destination - rclean [path] : perform a recursive '"'make clean ; make clear'"' - -Operation "src" can be abbrieviated to "s"' + rclean [path] : perform a recursive '"'make clean ; make clear'"'' } if [ -n "$XDG_DATA_HOME" ] @@ -30,10 +28,7 @@ fi usr_datapath="/usr/share/zcsf" -if [ -n "$CONFIGPATH" ] -then - local_datapath="$CONFIGPATH" -fi +[ -n "$CONFIGPATH" ] && local_datapath="$CONFIGPATH" header_ifndef() { @@ -76,7 +71,7 @@ load_env() CC=$(grep "CC=" "$MAKEFILE" | cut -d'=' -f2- | head -n1) fi - if [ "$CC" = "g++" ] || [ "$CPP" = "true" ] + if [ "$CC" = "g++" ] || [ "$CC" = "clang++" ] || [ "$CPP" = "true" ] then PP="pp" fi diff --git a/znotif/znotif b/znotif/znotif index 7192379..7545b93 100755 --- a/znotif/znotif +++ b/znotif/znotif @@ -23,24 +23,22 @@ error() { # $1 = message , $2 = title , $3 = time notify () { - if which kdialog >/dev/null - then + if which kdialog >/dev/null ; then kdialog --passivepopup "$1" "$3" --title "$2" - elif which notify-send >/dev/null - then + elif which notify-send >/dev/null ; then notify-send -t "$3" "$2" "$1" - else error "No supported notification" + else + error "No supported notification" fi } yesno () { - if which kdialog >/dev/null - then + if which kdialog >/dev/null ; then kdialog --yesno "$1" --title "$2" - elif which zenity - then + elif which zenity ; then zenity --question --text="$1" --title="$2" - else error "No supported prompt" + else + error "No supported prompt" fi } @@ -55,14 +53,14 @@ do T) title=$OPTARG ;; t) _arg_t=$OPTARG ;; w) opt_w=y ;; - \?) echo "Uknown option: $OPTARG" && usage && exit 2 ;; + *) echo "Unknown option: $OPTARG" >&2 ; usage ; exit 2 ;; esac done shift $((OPTIND-1)) -if [ $# -gt 0 ] -then +# exec and resolve message +if [ $# -gt 0 ] ; then [ -z "$opt_m" ] && message="'$*' finished" [ -z "$title" ] && title=$* "$@" @@ -71,8 +69,8 @@ else [ -z "$title" ] && title="Ping" fi -if [ -n "$opt_y" ] -then +# Send the notification +if [ -n "$opt_y" ] ; then yesno "$message" "$title" else notify "$message" "$title" "$_arg_t" diff --git a/zosu/zosu b/zosu/zosu index 95dadbe..9267218 100755 --- a/zosu/zosu +++ b/zosu/zosu @@ -23,18 +23,9 @@ Options: while getopts ":hc:" opt; do case $opt in - h) - usage - exit 0 - ;; - c) - config_file="$OPTARG" - ;; - \?) - echo "Uknown option: $OPTARG" - usage - exit 1 - ;; + h) usage ; exit 0 ;; + c) config_file="$OPTARG" ;; + *) echo "Unknown option: $OPTARG" >&2 ; usage ; exit 1 ;; esac done @@ -52,41 +43,15 @@ export vblank_mode=0 shift $((OPTIND-1)) -if [ -n "$1" ] -then - - if [ "$1" = "start" ]; then - shift $((OPTIND)) - wine $OSUDIR/osu\!.exe $@ - - elif [ "$1" = "kill" ]; then - wineserver -k - - elif [ "$1" = "sound" ]; then +case $1 in + start) shift $((OPTIND)) && wine "$OSUDIR/osu\!.exe" "$@" ;; + kill) wineserver -k ;; + sound) case $2 in - "pulse") - winetricks sound=pulse - ;; - "stable") - winetricks sound=pulse - ;; - "alsa") - winetricks sound=alsa - ;; - "lowlatency") - winetricks sound=alsa - ;; - *) - echo "$bin sound " - esac - - else - usage - exit 1 - fi - -else - usage - exit 1 -fi + pulse|stable) winetricks sound=pulse ;; + alsa|lowlatency) winetricks sound=alsa ;; + *) echo "$bin sound " >&2 ; exit 1 ;; + esac ;; + *) usage ; exit 1 ;; +esac diff --git a/zosu/zosu-install b/zosu/zosu-install index e79597d..eb765ff 100755 --- a/zosu/zosu-install +++ b/zosu/zosu-install @@ -1,37 +1,27 @@ #!/bin/sh -if [ "$OSUDIR" == "" ] ; then - OSUDIR='osu' -fi -if [ "$WINEDIR" == "" ] ; then - WINEDIR='$(pwd)/.wine' -fi +[ -z "$OSUDIR" ] && OSUDIR='osu' +[ -z "$WINEDIR" ] && WINEDIR='$(pwd)/.wine' + export WINEARCH=win32 export WINEPREFIX=$(echo "echo $WINEDIR" | sh) -silentmk() -{ - if [ ! -d "$1" ] ; then - mkdir "$1" - fi -} - pacman_packages() { sudo pacman -S --needed --noconfirm lib32-alsa-lib lib32-libpulse lib32-gnutls lib32-libxcomposite } echo_red() { - printf "\033[1;31m$1\033[0m\n" + printf "\033[1;31m%s\033[0m\n" "$*" } echo_blue() { - printf "\033[1;34m$1\033[0m\n" + printf "\033[1;34m%s\033[0m\n" "$*" } echo_yellow() { - printf "\033[1;33m$1\033[0m\n" + printf "\033[1;33m%s\033[0m\n" "$*" } echo_white() { - printf "\033[1;37m$1\033[0m\n" + printf "\033[1;37m%s\033[0m\n" "$*" } _done() { printf "\033[1;32mDone\033[0m\n\n" @@ -73,12 +63,8 @@ fi echo_white "Wine environment will be setup. This can take a very long time and may fail" read -p "Proceed? [Y/n]: " yn case $yn in - [Nn]* ) - echo_red "Aborting" - exit - ;; - * ) - ;; + [Nn]*) echo_red "Aborting" ; exit 1 ;; + *) ;; esac # The big one @@ -101,9 +87,8 @@ _done # ALSA audio read -p "Experimental audio lag lowering? [Y/n]: " yn case $yn in - [Nn]* ) - ;; - * ) + [Nn]* ) ;; + *) winetricks sound=alsa echo_yellow "If you encounter audio distortion, run 'zosu sound pulse' to revert" _done @@ -113,10 +98,8 @@ esac # install osu read -p "Insall fresh osu? [Y/n]: " yn case $yn in - [Nn]* ) - echo_blue "Provide a link '$OSUDIR' to the desired osu instance" - ;; - * ) + [Nn]*) echo_blue "Provide a link '$OSUDIR' to the desired osu instance" ;; + *) wget https://m1.ppy.sh/r/osu\!install.exe echo_white "Starting osu installer. Don't change the install directory" wine osu\!install.exe > /dev/null 2>&1 diff --git a/zosu/zosu-rater b/zosu/zosu-rater index b3ec21c..b0e10e8 100755 --- a/zosu/zosu-rater +++ b/zosu/zosu-rater @@ -3,6 +3,7 @@ if [ $# -lt 2 ] then echo "$0 " + exit 1 fi RATE="$1" @@ -13,8 +14,7 @@ OUTPUTFILE="$(echo "$2" | sed 's/\.osu//g' | cut -d']' -f1) x$RATE].osu" AUDIO=$(grep "AudioFilename:" "$FILE" | cut -d' ' -f2- | tr -d '\n\r') AUDIORATED=$(echo $AUDIO | cut -d'.' -f1)-x$RATE".mp3" -echo "" > $OUTPUTFILE -rm "$OUTPUTFILE" +echo "" > "$OUTPUTFILE" output_line () { printf "%s\r\n" "$1" >> $OUTPUTFILE diff --git a/zsync/zsync b/zsync/zsync index d7f0b1d..52ea504 100755 --- a/zsync/zsync +++ b/zsync/zsync @@ -418,7 +418,7 @@ do arg_c="$OPTARG" ;; h) usage && exit 1 ;; - \?) echo "Uknown option: $OPTARG" >&2 && usage && exit 1 ;; + \?) echo "Unknown option: $OPTARG" >&2 && usage && exit 1 ;; esac done shift $((OPTIND-1)) diff --git a/ztr/zdtol b/ztr/zdtol index 5bc5545..e867063 100755 --- a/ztr/zdtol +++ b/ztr/zdtol @@ -43,7 +43,7 @@ do _opt_d=y ;; \?) - echo "Uknown option: $OPTARG" >&2 + echo "Unknown option: $OPTARG" >&2 usage exit 1 ;; diff --git a/ztr/zltod b/ztr/zltod index afe42ed..fd01cdc 100755 --- a/ztr/zltod +++ b/ztr/zltod @@ -30,7 +30,7 @@ do _opt_f=y ;; \?) - echo "Uknown option: $OPTARG" >&2 + echo "Unknown option: $OPTARG" >&2 usage exit 1 ;; diff --git a/ztr/ztr b/ztr/ztr index 1e42216..caf2bb3 100755 --- a/ztr/ztr +++ b/ztr/ztr @@ -16,11 +16,10 @@ Options: gen_tr_lines_disk() { -# find /sys/block -maxdepth 1 cd /sys/block for I in * do - _t=$(zdtol $I | head -n1) + _t=$(zdtol "$I" | head -n1) [ -n "$_t" ] && printf "/dev/%s:%s\n" "$I" "$_t" done } @@ -42,8 +41,6 @@ fi DATA_PATH=$CONFIG_PATH/data/ -FILE=/dev/stdin - while getopts ":hPsf:pdl" opt; do _opt=y @@ -51,25 +48,21 @@ do h) usage && exit 0 ;; P) _opt_P=y ;; s) _opt_s=y ;; - f) - _opt_f=y + f) _opt_f=y _arg_f=$OPTARG _opt_data=y ;; - d) - _opt_d=y - _opt_data=y - ;; - p) - _opt_p=y - _opt_data=y - ;; - l) - _opt_l=y - _opt_data=y - ;; + d) _opt_d=y + _opt_data=y + ;; + p) _opt_p=y + _opt_data=y + ;; + l) _opt_l=y + _opt_data=y + ;; \?) - echo "Uknown option: $OPTARG" >&2 + echo "Unknown option: $OPTARG" >&2 usage exit 1 ;; @@ -78,40 +71,27 @@ done shift $((OPTIND-1)) -if [ -z "$_opt_data" ] -then +[ -z "$_opt_data" ] && { _opt_p=y _opt_d=y _opt_l=y _opt_L=y -fi +} mkdir -p "$DATA_PATH" -LINES="" -if [ -n "$_opt_f" ] -then - LINES="$(printf "%s\n%s" "$LINES" "$(cat "$_arg_f")" )" -fi -if [ -n "$_opt_l" ] -then - LINES="$(printf "%s\n%s" "$LINES" "$(cat "$DATA_PATH"/* 2>/dev/null)" )" -fi -if [ -n "$_opt_p" ] -then - LINES="$(printf "%s\n%s" "$LINES" "$(gen_tr_lines_part)" )" -fi -if [ -n "$_opt_d" ] -then - LINES="$(printf "%s\n%s" "$LINES" "$(gen_tr_lines_disk)" )" -fi +LINES="" +[ -n "$_opt_f" ] && LINES="$(printf "%s\n%s" "$LINES" "$(cat "$_arg_f")" )" +[ -n "$_opt_l" ] && LINES="$(printf "%s\n%s" "$LINES" "$(cat "$DATA_PATH"/* 2>/dev/null)" )" +[ -n "$_opt_p" ] && LINES="$(printf "%s\n%s" "$LINES" "$(gen_tr_lines_part)" )" +[ -n "$_opt_d" ] && LINES="$(printf "%s\n%s" "$LINES" "$(gen_tr_lines_disk)" )" LINES=$(echo "$LINES" | grep -v '^$') -if [ -n "$1" ] ; then - FILE="$1" -fi +FILE=/dev/stdin +[ -n "$1" ] && FILE="$1" + if [ -t 0 ] || [ -n "$_opt_P" ] && [ -z "$1" ] then diff --git a/zumask/zumask b/zumask/zumask index acdb0b9..53f6d47 100755 --- a/zumask/zumask +++ b/zumask/zumask @@ -2,14 +2,15 @@ shift $((OPTIND-1)) +# $@ = paths +default_umask() { + find "$@" -type d -print0 | xargs -0 chmod "$(umask -S)" && + find "$@" -type f -print0 | xargs -0 chmod "$(umask -S | tr -d 'x')" +} + if [ $# -gt 0 ] then - _path=$* + default_umask "$@" else - _path=$(pwd) + default_umask . fi - -#find "$_path" -type d -exec chmod $(umask -S) {} \; -#find "$_path" -type f -exec chmod $(umask -S | tr -d 'x') {} \; -chmod "$(umask -S)" $(find "$_path" -type d) -chmod "$(umask -S | tr -d 'x')" $(find "$_path" -type f)