From 1a4113e3cd3d955e8214e9308ef8a5f236e30a2c Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Tue, 19 Sep 2023 09:04:02 +0300 Subject: [PATCH] chore(scripts): shfmt scripts --- local/bin/fzf-tmux | 32 +++++++++++++++++++------------- local/bin/x-hr | 27 ++++++++++++++------------- scripts/install-git-crypt.sh | 1 - 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/local/bin/fzf-tmux b/local/bin/fzf-tmux index 17d6c87..8fe75c6 100755 --- a/local/bin/fzf-tmux +++ b/local/bin/fzf-tmux @@ -2,8 +2,9 @@ # fzf-tmux: starts fzf in a tmux pane # usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS] -fail() { - >&2 echo "$1" +fail() +{ + echo >&2 "$1" exit 2 } @@ -19,8 +20,9 @@ term="" [[ -n "$LINES" ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}") [[ -n "$COLUMNS" ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}") -help() { - >&2 echo 'usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS] +help() +{ + echo >&2 'usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS] LAYOUT OPTIONS: (default layout: -d 50%) @@ -55,7 +57,7 @@ while [[ $# -gt 0 ]]; do echo "fzf-tmux (with fzf $("$fzf" --version))" exit ;; - -p*|-w*|-h*|-x*|-y*|-d*|-u*|-r*|-l*) + -p* | -w* | -h* | -x* | -y* | -d* | -u* | -r* | -l*) if [[ "$arg" =~ ^-[pwhxy] ]]; then [[ "$opt" =~ "-E" ]] || opt="-E" elif [[ "$arg" =~ ^.[lr] ]]; then @@ -93,9 +95,9 @@ while [[ $# -gt 0 ]]; do elif [[ "$arg" =~ ^-[whxy] ]]; then opt="$opt ${arg:0:2}$size" elif [[ "$size" =~ %$ ]]; then - size=${size:0:((${#size}-1))} + size=${size:0:((${#size} - 1))} if [[ -n "$swap" ]]; then - opt="$opt -p $(( 100 - size ))" + opt="$opt -p $((100 - size))" else opt="$opt -p $size" fi @@ -106,7 +108,7 @@ while [[ $# -gt 0 ]]; do else max=$lines fi - size=$(( max - size )) + size=$((max - size)) [[ $size -lt 0 ]] && size=0 opt="$opt -l $size" else @@ -152,13 +154,14 @@ fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id" fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id" fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id" if tmux_win_opts=$(tmux show-options -p remain-on-exit \; show-options -p synchronize-panes 2> /dev/null); then - tmux_win_opts=( $(sed '/ off/d; s/synchronize-panes/set-option -p synchronize-panes/; s/remain-on-exit/set-option -p remain-on-exit/; s/$/ \\;/' <<< "$tmux_win_opts") ) + tmux_win_opts=($(sed '/ off/d; s/synchronize-panes/set-option -p synchronize-panes/; s/remain-on-exit/set-option -p remain-on-exit/; s/$/ \\;/' <<< "$tmux_win_opts")) tmux_off_opts='; set-option -p synchronize-panes off ; set-option -p remain-on-exit off' else - tmux_win_opts=( $(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/') ) + tmux_win_opts=($(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/')) tmux_off_opts='; set-window-option synchronize-panes off ; set-window-option remain-on-exit off' fi -cleanup() { +cleanup() +{ \rm -f $argsf $fifo1 $fifo2 $fifo3 # Restore tmux window options @@ -196,7 +199,7 @@ if [[ "$opt" =~ "-E" ]]; then exit 2 fi fi -[[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")" +[[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")" [[ -n "$FZF_DEFAULT_COMMAND" ]] && envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")" [[ -n "$RUNEWIDTH_EASTASIAN" ]] && envs="$envs RUNEWIDTH_EASTASIAN=$(printf %q "$RUNEWIDTH_EASTASIAN")" [[ -n "$BAT_THEME" ]] && envs="$envs BAT_THEME=$(printf %q "$BAT_THEME")" @@ -236,6 +239,9 @@ fi tmux \ split-window -c "$PWD" $opt "bash -c 'exec -a fzf bash $argsf'" $swap \ $tmux_off_opts \ - > /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; } + > /dev/null 2>&1 || { + "$fzf" "${args[@]}" + exit $? +} cat $fifo2 exit "$(cat $fifo3)" diff --git a/local/bin/x-hr b/local/bin/x-hr index 78893ff..745ff98 100755 --- a/local/bin/x-hr +++ b/local/bin/x-hr @@ -10,9 +10,9 @@ # Modified by Ismo Vuorinen 2023 # Determine width of terminal -hr_col_count="$( (tput cols - 4) )" +hr_col_count="$( (tput cols - 4))" if [ -z "${hr_col_count+set}" ] || [ "$hr_col_count" -lt 1 ]; then - hr_col_count="${COLUMNS:-80}" + hr_col_count="${COLUMNS:-80}" fi # Colors @@ -21,20 +21,21 @@ hr_color="${hr_color:=$CLR_RED}" hr_reset="\033[0m" # Prints the HR line -hr_draw_char() { - local CHAR="$1" - local LINE="" - LINE=$(printf "%*s" "$((hr_col_count - 3))" " ") - LINE="${LINE// /${CHAR}}" - echo -e "${hr_color}${LINE:0:${hr_col_count}}${hr_reset}" +hr_draw_char() +{ + local CHAR="$1" + local LINE="" + LINE=$(printf "%*s" "$((hr_col_count - 3))" " ") + LINE="${LINE// /${CHAR}}" + echo -e "${hr_color}${LINE:0:${hr_col_count}}${hr_reset}" } # Passes param and calls hr() -hr() { - for WORD in "${@:--}"; do - hr_draw_char "$WORD" - done +hr() +{ + for WORD in "${@:--}"; do + hr_draw_char "$WORD" + done } hr "$@" - diff --git a/scripts/install-git-crypt.sh b/scripts/install-git-crypt.sh index 230ca8b..803a11e 100755 --- a/scripts/install-git-crypt.sh +++ b/scripts/install-git-crypt.sh @@ -25,4 +25,3 @@ msg "Installing git-crypt" fi } msg_done "Done installing git-crypt" -