mirror of
https://github.com/jimeh/tmuxifier.git
synced 2026-02-19 01:46:40 +00:00
style(shell): improve shell script formatting and quoting
Apply shfmt formatting and fix some schellcheck complaints.
This commit is contained in:
@@ -45,15 +45,15 @@ fi
|
||||
# Parse given command
|
||||
command="$1"
|
||||
case "$command" in
|
||||
"" | "-h" | "--help" )
|
||||
"" | "-h" | "--help")
|
||||
echo -e "tmuxifier $(tmuxifier-version)\n$(tmuxifier-help)" >&2
|
||||
;;
|
||||
|
||||
"-v" | "--version" )
|
||||
"-v" | "--version")
|
||||
tmuxifier-version
|
||||
;;
|
||||
|
||||
* )
|
||||
*)
|
||||
! command_path="$(tmuxifier-resolve-command-path "$command")"
|
||||
|
||||
if [ -z "$command_path" ]; then
|
||||
|
||||
@@ -3,11 +3,11 @@ _tmuxifier() {
|
||||
local word="${COMP_WORDS[COMP_CWORD]}"
|
||||
|
||||
if [ "$COMP_CWORD" -eq 1 ]; then
|
||||
COMPREPLY=( $(compgen -W "$(tmuxifier commands)" -- "$word") )
|
||||
COMPREPLY=($(compgen -W "$(tmuxifier commands)" -- "$word"))
|
||||
else
|
||||
local command="${COMP_WORDS[1]}"
|
||||
local completions="$(tmuxifier completions "$command")"
|
||||
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
|
||||
COMPREPLY=($(compgen -W "$completions" -- "$word"))
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -214,8 +214,8 @@ load_window() {
|
||||
if [ $# -gt 1 ]; then
|
||||
window="$2"
|
||||
else
|
||||
window="${1/%.window.sh}"
|
||||
window="${window/%.sh}"
|
||||
window="${1/%.window.sh/}"
|
||||
window="${window/%.sh/}"
|
||||
fi
|
||||
source "$file"
|
||||
window=
|
||||
@@ -258,8 +258,8 @@ load_session() {
|
||||
if [ $# -gt 1 ]; then
|
||||
session="$2"
|
||||
else
|
||||
session="${1/%.session.sh}"
|
||||
session="${session/%.sh}"
|
||||
session="${1/%.session.sh/}"
|
||||
session="${session/%.sh/}"
|
||||
fi
|
||||
|
||||
set_default_path=true
|
||||
@@ -308,7 +308,7 @@ initialize_session() {
|
||||
|
||||
$set_default_path && tmuxifier-tmux \
|
||||
set-option -t "$session:" \
|
||||
default-path "$session_root" 1>/dev/null
|
||||
default-path "$session_root" 1> /dev/null
|
||||
fi
|
||||
|
||||
# Tmux 1.9 and later.
|
||||
@@ -344,13 +344,12 @@ initialize_session() {
|
||||
# created, but already existed, then we'll need to specifically switch to it.
|
||||
#
|
||||
finalize_and_go_to_session() {
|
||||
! tmuxifier-tmux kill-window -t "$session:999" 2>/dev/null
|
||||
! tmuxifier-tmux kill-window -t "$session:999" 2> /dev/null
|
||||
if [[ "$(tmuxifier-current-session)" != "$session" ]]; then
|
||||
__go_to_session
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Internal functions
|
||||
#
|
||||
@@ -368,7 +367,7 @@ __expand_path() {
|
||||
|
||||
__get_first_window_index() {
|
||||
local index=$(tmuxifier-tmux list-windows -t "$session:" \
|
||||
-F "#{window_index}" 2>/dev/null)
|
||||
-F "#{window_index}" 2> /dev/null)
|
||||
|
||||
if [ -n "$index" ]; then
|
||||
echo "$index" | head -1
|
||||
@@ -379,10 +378,10 @@ __get_first_window_index() {
|
||||
|
||||
__get_current_window_index() {
|
||||
local lookup=$(tmuxifier-tmux list-windows -t "$session:" \
|
||||
-F "#{window_active}:#{window_index}" 2>/dev/null | grep "^1:")
|
||||
-F "#{window_active}:#{window_index}" 2> /dev/null | grep "^1:")
|
||||
|
||||
if [ -n "$lookup" ]; then
|
||||
echo "${lookup/1:}"
|
||||
echo "${lookup/1:/}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
calling-help() {
|
||||
if [[ " $@ " != *" --help "* ]] && [[ " $@ " != *" -h "* ]]; then
|
||||
if [[ " $* " != *" --help "* ]] && [[ " $* " != *" -h "* ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
calling-complete() {
|
||||
if [[ " $@ " != *" --complete "* ]]; then
|
||||
if [[ " $* " != *" --complete "* ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -14,33 +14,34 @@ 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"
|
||||
;;
|
||||
* )
|
||||
*)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -20,11 +20,11 @@ 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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,25 +14,25 @@ if [ -z "$shell" ]; then
|
||||
fi
|
||||
|
||||
case "$shell" in
|
||||
bash )
|
||||
bash)
|
||||
profile='~/.bash_profile'
|
||||
;;
|
||||
zsh )
|
||||
zsh)
|
||||
profile='~/.zshrc'
|
||||
;;
|
||||
ksh )
|
||||
ksh)
|
||||
profile='~/.profile'
|
||||
;;
|
||||
csh )
|
||||
csh)
|
||||
profile='~/.cshrc'
|
||||
;;
|
||||
tcsh )
|
||||
tcsh)
|
||||
profile='~/.tcshrc'
|
||||
;;
|
||||
fish )
|
||||
fish)
|
||||
profile='~/.config/fish/config.fish'
|
||||
;;
|
||||
* )
|
||||
*)
|
||||
profile='shell init file'
|
||||
;;
|
||||
esac
|
||||
@@ -45,15 +45,15 @@ 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,17 +64,17 @@ 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
|
||||
@@ -83,7 +83,7 @@ case "$shell" in
|
||||
echo "source \"\$TMUXIFIER/init.fish\";"
|
||||
fi
|
||||
;;
|
||||
* )
|
||||
*)
|
||||
echo "export TMUXIFIER=\"$TMUXIFIER\";"
|
||||
echo "source \"\$TMUXIFIER/init.sh\";"
|
||||
;;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 [ ! -z "$TMUX" ]; then
|
||||
session="$(tmuxifier-current-session)"
|
||||
load_window "$1"
|
||||
else
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -19,16 +19,16 @@ fi
|
||||
|
||||
# The vercomp() function is shamelessly ripped/borrowed from the following
|
||||
# StackOverflow answer: http://stackoverflow.com/a/4025065/42146
|
||||
vercomp () {
|
||||
vercomp() {
|
||||
if [[ $1 == $2 ]]; then return 0; fi
|
||||
|
||||
local IFS=.
|
||||
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 +63,8 @@ else
|
||||
|
||||
vercomp "$version" "$1"
|
||||
case $? in
|
||||
0) echo '=';;
|
||||
1) echo '>';;
|
||||
2) echo '<';;
|
||||
0) echo '=' ;;
|
||||
1) echo '>' ;;
|
||||
2) echo '<' ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user