wip(commands): re-implement core commands as bash functions

Re-implement all libexec executables as bash functions, with the goal of
being able build a single standalone execuable bash script for
tmuxifier.
This commit is contained in:
2025-12-01 23:17:41 +00:00
parent f268c12f3f
commit b2a67705b6
8 changed files with 240 additions and 174 deletions

View File

@@ -1,47 +1,6 @@
#! /usr/bin/env bash
set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
source "$TMUXIFIER/lib/load.sh"
# Provide tmuxifier help
if calling-help "$@"; then
echo "usage: tmuxifier alias <alias>
Resolve a command alias to it's full name."
exit
fi
case "$1" in
"session" | "ses" | "s")
echo "load-session"
;;
"window" | "win" | "w")
echo "load-window"
;;
"new-ses" | "nses" | "ns")
echo "new-session"
;;
"new-win" | "nwin" | "nw")
echo "new-window"
;;
"edit-ses" | "eses" | "es")
echo "edit-session"
;;
"edit-win" | "ewin" | "ew")
echo "edit-window"
;;
"l")
echo "list"
;;
"list-ses" | "lses" | "ls")
echo "list-sessions"
;;
"list-win" | "lwin" | "lw")
echo "list-windows"
;;
*)
exit 1
;;
esac
tmuxifier-alias "$@"

View File

@@ -1,30 +1,6 @@
#! /usr/bin/env bash
set -e
[ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
source "$TMUXIFIER/lib/load.sh"
# Provide tmuxifier help
if calling-help "$@"; then
echo "usage: tmuxifier resolve-command-path <command_or_alias>
Outputs the absolute path to the given command or command alias."
exit
fi
if [ -n "$1" ]; then
! command_path="$(command -v "tmuxifier-$1")"
if [ -z "$command_path" ]; then
resolved="$(tmuxifier-alias "$1")"
if [ -n "$resolved" ]; then
! command_path="$(command -v "tmuxifier-$resolved")"
fi
fi
fi
if [ -n "$command_path" ]; then
echo "$command_path"
else
exit 1
fi
tmuxifier-resolve-command-path "$@"

View File

@@ -1,70 +1,6 @@
#! /usr/bin/env bash
shopt -s extglob
[ -n "$TMUXIFIER_DEBUG" ] && set -x
# Load internal utility functions.
source "$TMUXIFIER/lib/util.sh"
source "$TMUXIFIER/lib/load.sh"
# Provide tmuxifier help
if calling-help "$@"; then
echo "usage: tmuxifier tmux-version [<target-version>]
Outputs current Tmux version. If given optional target-version it outputs one
of three possible characters indicating if the current Tmux version number is
equal to, less than, or greater than the <target-version>.
The three possible outputs are \"=\", \"<\", and \">\"."
exit
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
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 = 0; i < ${#ver1[@]}; i++)); do
# fill empty fields in ver2 with zeros
if [[ -z ${ver2[i]} ]]; then ver2[i]=0; fi
if ((10#${ver1[i]} > 10#${ver2[i]})); then
return 1
elif ((10#${ver1[i]} < 10#${ver2[i]})); then
return 2
fi
done
return 0
}
version=$(tmux -V)
version=${version/tmux /}
# Fix for tmux next-* versions
version=${version/next-/}
if [ -z "$1" ]; then
echo "$version"
exit
fi
if [ "$version" == "master" ]; then
# When version string is "master", tmux was compiled from source, and we
# assume it's later than whatever the <target-version> is.
echo '>'
else
# Fix for "1.9a" version comparison, as vercomp() can only deal with
# purely numeric version numbers.
version=${version//+([a-zA-Z])/}
vercomp "$version" "$1"
case $? in
0) echo '=' ;;
1) echo '>' ;;
2) echo '<' ;;
esac
fi
tmuxifier-tmux-version "$@"