chore: format files with shfmt and resolve most shellcheck complaints

This commit is contained in:
2024-02-18 02:03:37 +00:00
parent 6cd89beb5e
commit 631e09f428
28 changed files with 160 additions and 140 deletions

View File

@@ -14,33 +14,37 @@ Resolve a command alias to it's full name."
fi
case "$1" in
"session" | "ses" | "s" )
"session" | "ses" | "s")
echo "load-session"
;;
"window" | "win" | "w" )
"window" | "win" | "w")
echo "load-window"
;;
"new-ses" | "nses" | "ns" )
"new-ses" | "nses" | "ns")
echo "new-session"
;;
"new-win" | "nwin" | "nw" )
"new-win" | "nwin" | "nw")
echo "new-window"
;;
"edit-ses" | "eses" | "es" )
"edit-ses" | "eses" | "es")
echo "edit-session"
;;
"edit-win" | "ewin" | "ew" )
"edit-win" | "ewin" | "ew")
echo "edit-window"
;;
"l" )
"l")
echo "list"
;;
"list-ses" | "lses" | "ls" )
"list-ses" | "lses" | "ls")
echo "list-sessions"
;;
"list-win" | "lwin" | "lw" )
"list-win" | "lwin" | "lw")
echo "list-windows"
;;
* )
"completion")
echo "completions"
;;
*)
exit 1
;;
esac

View File

@@ -16,7 +16,8 @@ fi
shopt -s nullglob
{ for path in ${PATH//:/$'\n'}; do
{
for path in ${PATH//:/$'\n'}; do
for command in "${path}/tmuxifier-"*; do
command="${command##*tmuxifier-}"
echo "$command"

View File

@@ -7,7 +7,9 @@ source "$TMUXIFIER/lib/util.sh"
# Provide tmuxifier help
if calling-help "$@"; then
echo "usage: tmuxifier completion <command>
echo "usage: tmuxifier completions <command>
Aliases: completion
Print a list of available completions for specified command."
exit
@@ -20,15 +22,15 @@ if calling-complete "$@"; then
fi
has-completions() {
grep -i "^# Provide tmuxifier completions" "$1" >/dev/null
grep -i "^# Provide tmuxifier completions" "$1" > /dev/null
}
if [ -z "$1" ]; then
echo "$(tmuxifier-help completions $@)" >&2
tmuxifier-help completions "$@" >&2
exit 1
fi
! command_path="$(tmuxifier-resolve-command-path "$1")"
command_path="$(tmuxifier-resolve-command-path "$1")" || true
if [ -n "$command_path" ] && has-completions "$command_path"; then
shift

View File

@@ -14,8 +14,8 @@ Outputs the name of the current Tmux session."
fi
if [ -n "$TMUX" ]; then
for item in $(tmuxifier-tmux list-pane -F "#{session_name}");do
echo $item
for item in $(tmuxifier-tmux list-pane -F "#{session_name}"); do
echo "$item"
exit 0
done
fi

View File

@@ -22,7 +22,7 @@ if calling-complete "$@"; then
fi
if [ -z "$1" ]; then
echo "$(tmuxifier-help edit-session $@)" >&2
tmuxifier-help edit-session "$@" >&2
exit 1
fi

View File

@@ -22,7 +22,7 @@ if calling-complete "$@"; then
fi
if [ -z "$1" ]; then
echo "$(tmuxifier-help edit-window $@)" >&2
tmuxifier-help edit-window "$@" >&2
exit 1
fi

View File

@@ -18,7 +18,7 @@ if calling-complete "$@"; then
fi
has-help() {
grep -i "^# Provide tmuxifier help" "$1" >/dev/null
grep -i "^# Provide tmuxifier help" "$1" > /dev/null
}
if [ -z "$1" ]; then
@@ -43,7 +43,7 @@ See 'tmuxifier help <command>' for information on a specific command."
exit
fi
! command_path="$(tmuxifier-resolve-command-path "$1")"
command_path="$(tmuxifier-resolve-command-path "$1")" || true
if [ -z "$command_path" ]; then
echo "tmuxifier: no such command '$1'" >&2

View File

@@ -2,6 +2,9 @@
set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
# Set shell to first argument that is not "-", "-h" or "--help".
for arg in "$@"; do
if [ "$arg" != "-" ] && [ "$arg" != "-h" ] && [ "$arg" != "--help" ]; then
@@ -14,46 +17,46 @@ if [ -z "$shell" ]; then
fi
case "$shell" in
bash )
profile='~/.bash_profile'
bash)
profile='.bash_profile'
;;
zsh )
profile='~/.zshrc'
zsh)
profile='.zshrc'
;;
ksh )
profile='~/.profile'
ksh)
profile='.profile'
;;
csh )
profile='~/.cshrc'
csh)
profile='.cshrc'
;;
tcsh )
profile='~/.tcshrc'
tcsh)
profile='.tcshrc'
;;
fish )
profile='~/.config/fish/config.fish'
fish)
profile='.config/fish/config.fish'
;;
* )
*)
profile='shell init file'
;;
esac
# Provide tmuxifier help
if [[ " $@ " == *" --help "* ]]; then
if calling-help "$@"; then
echo "usage: tmuxifier init -
Load Tmuxifier by adding the following to your ${profile}:
Load Tmuxifier by adding the following to your ~/${profile}:
"
case "$shell" in
csh | tcsh )
csh | tcsh)
echo " eval \`tmuxifier init -\`
"
;;
fish )
fish)
echo " eval (tmuxifier init -)
"
;;
* )
*)
echo " eval \"\$(tmuxifier init -)\"
"
;;
@@ -64,26 +67,26 @@ Load Tmuxifier by adding the following to your ${profile}:
fi
# Print help if "-" argument is not given
if [[ " $@ " != *" - "* ]]; then
echo "$(tmuxifier-help init $@)" >&2
if [[ " $* " != *" - "* ]]; then
tmuxifier-help init "$@" >&2
exit 1
fi
case "$shell" in
csh | tcsh )
csh | tcsh)
echo "setenv TMUXIFIER \"$TMUXIFIER\";"
echo "source \"\$TMUXIFIER/init.tcsh\";"
;;
fish )
fish)
echo "set -gx TMUXIFIER \"$TMUXIFIER\";"
# fish shell 2.0.0 does not have the source alias
if [[ $(fish --version 2>&1 | awk -F'version ' '{print $2}') = '2.0.0' ]]; then
echo ". \"\$TMUXIFIER/init.fish\";"
else
echo "source \"\$TMUXIFIER/init.fish\";"
fi
fi
;;
* )
*)
echo "export TMUXIFIER=\"$TMUXIFIER\";"
echo "source \"\$TMUXIFIER/init.sh\";"
;;

View File

@@ -30,7 +30,7 @@ if calling-complete "$@"; then
fi
if [ -z "$1" ]; then
echo "$(tmuxifier-help load-session $@)" >&2
tmuxifier-help load-session "$@" >&2
exit 1
fi

View File

@@ -26,14 +26,14 @@ if calling-complete "$@"; then
fi
if [ -z "$1" ]; then
echo "$(tmuxifier-help load-window $@)" >&2
tmuxifier-help load-window "$@" >&2
exit 1
fi
# Load runtime functions.
source "$TMUXIFIER/lib/runtime.sh"
if [ ! -z $TMUX ]; then
if [ -n "$TMUX" ]; then
session="$(tmuxifier-current-session)"
load_window "$1"
else

View File

@@ -22,7 +22,7 @@ if calling-complete "$@"; then
fi
if [ -z "$1" ]; then
echo "$(tmuxifier-help new-session $@)" >&2
tmuxifier-help new-session "$@" >&2
exit 1
fi

View File

@@ -22,7 +22,7 @@ if calling-complete "$@"; then
fi
if [ -z "$1" ]; then
echo "$(tmuxifier-help new-window $@)" >&2
tmuxifier-help new-window "$@" >&2
exit 1
fi

View File

@@ -14,11 +14,11 @@ Outputs the absolute path to the given command or command alias."
fi
if [ -n "$1" ]; then
! command_path="$(command -v "tmuxifier-$1")"
command_path="$(command -v "tmuxifier-$1")" || true
if [ -z "$command_path" ]; then
resolved="$(tmuxifier-alias "$1")"
if [ -n "$resolved" ]; then
! command_path="$(command -v "tmuxifier-$resolved")"
command_path="$(command -v "tmuxifier-$resolved")" || true
fi
fi
fi

View File

@@ -2,4 +2,5 @@
set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x
# shellcheck disable=SC2086
tmux $TMUXIFIER_TMUX_OPTS "$@"

View File

@@ -19,16 +19,17 @@ fi
# The vercomp() function is shamelessly ripped/borrowed from the following
# StackOverflow answer: http://stackoverflow.com/a/4025065/42146
vercomp () {
if [[ $1 == $2 ]]; then return 0; fi
vercomp() {
if [[ "$1" == "$2" ]]; then return 0; fi
local IFS=.
# shellcheck disable=SC2206
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do ver1[i]=0; done
for ((i = ${#ver1[@]}; i < ${#ver2[@]}; i++)); do ver1[i]=0; done
for ((i=0; i<${#ver1[@]}; i++)); do
for ((i = 0; i < ${#ver1[@]}; i++)); do
# fill empty fields in ver2 with zeros
if [[ -z ${ver2[i]} ]]; then ver2[i]=0; fi
@@ -63,8 +64,8 @@ else
vercomp "$version" "$1"
case $? in
0) echo '=';;
1) echo '>';;
2) echo '<';;
0) echo '=' ;;
1) echo '>' ;;
2) echo '<' ;;
esac
fi