Skip to content

Instantly share code, notes, and snippets.

@andyHa
Last active February 9, 2024 08:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andyHa/8aad560aa4eb0745b9c8 to your computer and use it in GitHub Desktop.
Save andyHa/8aad560aa4eb0745b9c8 to your computer and use it in GitHub Desktop.
X-Tool - A super small but handy tool to call frequently used shell commands...
#
# Made with all the love in the world
# by scireum in Remshalden, Germany
#
# Copyright by scireum GmbH
# http://www.scireum.de - info@scireum.de
# written by Andreas Haufler (aha@scireum.de)
# Licensed under the MIT license: http://opensource.org/licenses/MIT
#
# X-TOOL provides a very simple tool for invoking frequent commands.
# Those commands can be defined by setting X_OPTIONS e.g. in .bashrc:
# export X_OPTIONS=("htop" "cd" "ifconfig")
# . ~/xtool.sh <- Change this path to where ever you store the
# xtool.sh file
#
# If an option starts with ? the user has to acknoledge the command
# before its execution (everything after the ?). This can be useful
# for commands like 'service restart xxx'
echo "scireum X-Tool is available by calling 'x' :-)"
if [ -z "$X_OPTIONS" ]; then
echo "Set X_OPTIONS to define choices..."
fi
x() {
PS3="Please choose: "
if [ -z "$X_OPTIONS" ]; then
X_OPTIONS=("htop" "cd /var/log" "cd")
fi
select opt in "${X_OPTIONS[@]}"
do
if [ ${opt:0:1} = "?" ]; then
read -r -p "Are you sure? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
opt=${opt:1}
;;
*)
opt=""
;;
esac
fi
eval $opt
break
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment