cleanup for new folder
This commit is contained in:
parent
d9ca82a51b
commit
005541a96f
50 changed files with 0 additions and 10356 deletions
340
bin/desk
340
bin/desk
|
@ -1,340 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# vim: set filetype=sh:
|
||||
|
||||
PREFIX="${DESK_DIR:-$HOME/.desk}"
|
||||
DESKS="${DESK_DESKS_DIR:-$PREFIX/desks}"
|
||||
DESKFILE_NAME=Deskfile
|
||||
|
||||
|
||||
## Commands
|
||||
|
||||
cmd_version() {
|
||||
echo "◲ desk 0.6.0"
|
||||
}
|
||||
|
||||
|
||||
cmd_usage() {
|
||||
cmd_version
|
||||
echo
|
||||
cat <<_EOF
|
||||
Usage:
|
||||
|
||||
$PROGRAM
|
||||
List the current desk and any associated aliases. If no desk
|
||||
is being used, display available desks.
|
||||
$PROGRAM init
|
||||
Initialize desk configuration.
|
||||
$PROGRAM (list|ls)
|
||||
List all desks along with a description.
|
||||
$PROGRAM (.|go) [<desk-name-or-path> [shell-args...]]
|
||||
Activate a desk. Extra arguments are passed onto shell. If called with
|
||||
no arguments, look for a Deskfile in the current directory. If not a
|
||||
recognized desk, try as a path to directory containing a Deskfile.
|
||||
$PROGRAM run <desk-name> '<cmd>'
|
||||
$PROGRAM run <desk-name> <cmd> <arg>...
|
||||
Run a command within a desk's environment then exit. In the first form
|
||||
shell expansion is performed. In the second form, the argument vector
|
||||
is executed as is.
|
||||
$PROGRAM edit [desk-name]
|
||||
Edit (or create) a deskfile with the name specified, otherwise
|
||||
edit the active deskfile.
|
||||
$PROGRAM help
|
||||
Show this text.
|
||||
$PROGRAM version
|
||||
Show version information.
|
||||
|
||||
Since desk spawns a shell, to deactivate and "pop" out a desk, you
|
||||
simply need to exit or otherwise end the current shell process.
|
||||
_EOF
|
||||
}
|
||||
|
||||
cmd_init() {
|
||||
if [ -d "$PREFIX" ]; then
|
||||
echo "Desk dir already exists at ${PREFIX}"
|
||||
exit 1
|
||||
fi
|
||||
read -p "Where do you want to store your deskfiles? (default: ${PREFIX}): " \
|
||||
NEW_PREFIX
|
||||
[ -z "${NEW_PREFIX}" ] && NEW_PREFIX="$PREFIX"
|
||||
|
||||
if [ ! -d "${NEW_PREFIX}" ]; then
|
||||
echo "${NEW_PREFIX} doesn't exist, attempting to create."
|
||||
mkdir -p "$NEW_PREFIX/desks"
|
||||
fi
|
||||
|
||||
local SHELLTYPE=$(get_running_shell)
|
||||
|
||||
case "${SHELLTYPE}" in
|
||||
bash) local SHELLRC="${HOME}/.bashrc" ;;
|
||||
fish) local SHELLRC="${HOME}/.config/fish/config.fish" ;;
|
||||
zsh) local SHELLRC="${HOME}/.zshrc" ;;
|
||||
esac
|
||||
|
||||
read -p "Where's your shell rc file? (default: ${SHELLRC}): " \
|
||||
USER_SHELLRC
|
||||
[ -z "${USER_SHELLRC}" ] && USER_SHELLRC="$SHELLRC"
|
||||
if [ ! -f "$USER_SHELLRC" ]; then
|
||||
echo "${USER_SHELLRC} doesn't exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "\n# Hook for desk activation\n" >> "$USER_SHELLRC"
|
||||
|
||||
# Since the hook is appended to the rc file, its exit status becomes
|
||||
# the exit status of `source $USER_SHELLRC` which typically
|
||||
# indicates if something went wrong. If $DESK_ENV is void, `test`
|
||||
# sets exit status to 1. That, however, is part of desk's normal
|
||||
# operation, so we clear exit status after that.
|
||||
if [ "$SHELLTYPE" == "fish" ]; then
|
||||
echo "test -n \"\$DESK_ENV\"; and . \"\$DESK_ENV\"; or true" >> "$USER_SHELLRC"
|
||||
else
|
||||
echo "[ -n \"\$DESK_ENV\" ] && source \"\$DESK_ENV\" || true" >> "$USER_SHELLRC"
|
||||
fi
|
||||
|
||||
echo "Done. Start adding desks to ${NEW_PREFIX}/desks!"
|
||||
}
|
||||
|
||||
|
||||
cmd_go() {
|
||||
# TODESK ($1) may either be
|
||||
#
|
||||
# - the name of a desk in $DESKS/
|
||||
# - a path to a Deskfile
|
||||
# - a directory containing a Deskfile
|
||||
# - empty -> `./Deskfile`
|
||||
#
|
||||
local TODESK="$1"
|
||||
local DESKEXT=$(get_deskfile_extension)
|
||||
local DESKPATH="$(find "${DESKS}/" -name "${TODESK}${DESKEXT}" 2>/dev/null)"
|
||||
|
||||
local POSSIBLE_DESKFILE_DIR="${TODESK%$DESKFILE_NAME}"
|
||||
if [ -z "$POSSIBLE_DESKFILE_DIR" ]; then
|
||||
POSSIBLE_DESKFILE_DIR="."
|
||||
fi
|
||||
|
||||
# If nothing could be found in $DESKS/, check to see if this is a path to
|
||||
# a Deskfile.
|
||||
if [[ -z "$DESKPATH" && -d "$POSSIBLE_DESKFILE_DIR" ]]; then
|
||||
if [ ! -f "${POSSIBLE_DESKFILE_DIR}/${DESKFILE_NAME}" ]; then
|
||||
echo "No Deskfile found in '${POSSIBLE_DESKFILE_DIR}'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local REALPATH=$( cd $POSSIBLE_DESKFILE_DIR && pwd )
|
||||
DESKPATH="${REALPATH}/${DESKFILE_NAME}"
|
||||
TODESK=$(basename "$REALPATH")
|
||||
fi
|
||||
|
||||
# Shift desk name so we can forward on all arguments to the shell.
|
||||
shift;
|
||||
|
||||
if [ -z "$DESKPATH" ]; then
|
||||
echo "Desk $TODESK (${TODESK}${DESKEXT}) not found in $DESKS"
|
||||
exit 1
|
||||
else
|
||||
local SHELL_EXEC="$(get_running_shell)"
|
||||
DESK_NAME="${TODESK}" DESK_ENV="${DESKPATH}" exec "${SHELL_EXEC}" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
cmd_run() {
|
||||
local TODESK="$1"
|
||||
shift;
|
||||
if [ $# -eq 1 ]; then
|
||||
cmd_go "$TODESK" -ic "$1"
|
||||
else
|
||||
cmd_go "$TODESK" -ic '"$@"' -- "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# Usage: desk list [options]
|
||||
# Description: List all desks along with a description
|
||||
# --only-names: List only the names of the desks
|
||||
# --no-format: Use ' - ' to separate names from descriptions
|
||||
cmd_list() {
|
||||
if [ ! -d "${DESKS}/" ]; then
|
||||
echo "No desk dir! Run 'desk init'."
|
||||
exit 1
|
||||
fi
|
||||
local SHOW_DESCRIPTIONS DESKEXT AUTO_ALIGN name desc len longest out
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--only-names) SHOW_DESCRIPTIONS=false && AUTO_ALIGN=false ;;
|
||||
--no-format) AUTO_ALIGN=false ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
DESKEXT=$(get_deskfile_extension)
|
||||
out=""
|
||||
longest=0
|
||||
|
||||
while read -d '' -r f; do
|
||||
name=$(basename "${f/${DESKEXT}//}")
|
||||
if [[ "$SHOW_DESCRIPTIONS" = false ]]; then
|
||||
out+="$name"$'\n'
|
||||
else
|
||||
desc=$(echo_description "$f")
|
||||
out+="$name - $desc"$'\n'
|
||||
len=${#name}
|
||||
(( len > longest )) && longest=$len
|
||||
fi
|
||||
done < <(find "${DESKS}/" -name "*${DESKEXT}" -print0)
|
||||
if [[ "$AUTO_ALIGN" != false ]]; then
|
||||
print_aligned "$out" "$longest"
|
||||
else
|
||||
printf "%s" "$out"
|
||||
fi
|
||||
}
|
||||
|
||||
# Usage: desk [options]
|
||||
# Description: List the current desk and any associated aliases. If no desk is being used, display available desks
|
||||
# --no-format: Use ' - ' to separate alias/export/function names from their descriptions
|
||||
cmd_current() {
|
||||
if [ -z "$DESK_ENV" ]; then
|
||||
printf "No desk activated.\n\n%s" "$(cmd_list)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local DESKPATH=$DESK_ENV
|
||||
local CALLABLES=$(get_callables "$DESKPATH")
|
||||
local AUTO_ALIGN len longest out
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--no-format) AUTO_ALIGN=false ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
printf "%s - %s\n" "$DESK_NAME" "$(echo_description "$DESKPATH")"
|
||||
|
||||
if [[ -n "$CALLABLES" ]]; then
|
||||
|
||||
longest=0
|
||||
out=$'\n'
|
||||
for NAME in $CALLABLES; do
|
||||
# Last clause in the grep regexp accounts for fish functions.
|
||||
len=$((${#NAME} + 2))
|
||||
(( len > longest )) && longest=$len
|
||||
local DOCLINE=$(
|
||||
grep -B 1 -E \
|
||||
"^(alias ${NAME}=|export ${NAME}=|(function )?${NAME}( )?\()|function $NAME" "$DESKPATH" \
|
||||
| grep "#")
|
||||
|
||||
if [ -z "$DOCLINE" ]; then
|
||||
out+=" ${NAME}"$'\n'
|
||||
else
|
||||
out+=" ${NAME} - ${DOCLINE##\# }"$'\n'
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$AUTO_ALIGN" != false ]]; then
|
||||
print_aligned "$out" "$longest"
|
||||
else
|
||||
printf "%s" "$out"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
cmd_edit() {
|
||||
if [ $# -eq 0 ]; then
|
||||
if [ "$DESK_NAME" == "" ]; then
|
||||
echo "No desk activated."
|
||||
exit 3
|
||||
fi
|
||||
local DESKNAME_TO_EDIT="$DESK_NAME"
|
||||
elif [ $# -eq 1 ]; then
|
||||
local DESKNAME_TO_EDIT="$1"
|
||||
else
|
||||
echo "Usage: ${PROGRAM} edit [desk-name]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local DESKEXT=$(get_deskfile_extension)
|
||||
local EDIT_PATH="${DESKS}/${DESKNAME_TO_EDIT}${DESKEXT}"
|
||||
|
||||
${EDITOR:-vi} "$EDIT_PATH"
|
||||
}
|
||||
|
||||
## Utilities
|
||||
|
||||
FNAME_CHARS='[a-zA-Z0-9_-]'
|
||||
|
||||
# Echo the description of a desk. $1 is the deskfile.
|
||||
echo_description() {
|
||||
local descline=$(grep -E "#\s+Description" "$1")
|
||||
echo "${descline##*Description: }"
|
||||
}
|
||||
|
||||
# Echo a list of aliases, exports, and functions for a given desk
|
||||
get_callables() {
|
||||
local DESKPATH=$1
|
||||
grep -E "^(alias |export |(function )?${FNAME_CHARS}+ ?\()|function $NAME" "$DESKPATH" \
|
||||
| sed 's/alias \([^= ]*\)=.*/\1/' \
|
||||
| sed 's/export \([^= ]*\)=.*/\1/' \
|
||||
| sed -E "s/(function )?(${FNAME_CHARS}+) ?\(\).*/\2/" \
|
||||
| sed -E "s/function (${FNAME_CHARS}+).*/\1/"
|
||||
}
|
||||
|
||||
get_running_shell() {
|
||||
# Echo the name of the parent shell via procfs, if we have it available.
|
||||
# Otherwise, try to use ps with bash's parent pid.
|
||||
if [ -e /proc ]; then
|
||||
# Get cmdline procfile of the process running this script.
|
||||
local CMDLINE_FILE="/proc/$(grep PPid /proc/$$/status | cut -f2)/cmdline"
|
||||
|
||||
if [ -f "$CMDLINE_FILE" ]; then
|
||||
# Strip out any verion that may be attached to the shell executable.
|
||||
# Strip leading dash for login shells.
|
||||
local CMDLINE_SHELL=$(sed -r -e 's/\x0.*//' -e 's/^-//' "$CMDLINE_FILE")
|
||||
fi
|
||||
else
|
||||
# Strip leading dash for login shells.
|
||||
# If the parent process is a login shell, guess bash.
|
||||
local CMDLINE_SHELL=$(ps -o comm= -p $PPID | tail -1 | sed -e 's/login/bash/' -e 's/^-//')
|
||||
fi
|
||||
|
||||
if [ ! -z "$CMDLINE_SHELL" ]; then
|
||||
basename "$CMDLINE_SHELL"
|
||||
exit
|
||||
fi
|
||||
|
||||
# Fall back to $SHELL otherwise.
|
||||
basename "$SHELL"
|
||||
exit
|
||||
}
|
||||
|
||||
# Echo the extension of recognized deskfiles (.fish for fish)
|
||||
get_deskfile_extension() {
|
||||
if [ "$(get_running_shell)" == "fish" ]; then
|
||||
echo '.fish'
|
||||
else
|
||||
echo '.sh'
|
||||
fi
|
||||
}
|
||||
|
||||
# Echo first argument as key/value pairs aligned into two columns; second argument is the longest key
|
||||
print_aligned() {
|
||||
local out=$1 longest=$2
|
||||
printf "%s" "$out" | awk -v padding="$longest" -F' - ' '{
|
||||
printf "%-*s %s\n", padding, $1, substr($0, index($0, " - ")+2, length($0))
|
||||
}'
|
||||
}
|
||||
|
||||
|
||||
PROGRAM="${0##*/}"
|
||||
|
||||
case "$1" in
|
||||
init) shift; cmd_init "$@" ;;
|
||||
help|--help) shift; cmd_usage "$@" ;;
|
||||
version|--version) shift; cmd_version "$@" ;;
|
||||
ls|list) shift; cmd_list "$@" ;;
|
||||
go|.) shift; cmd_go "$@" ;;
|
||||
run) shift; cmd_run "$@" ;;
|
||||
edit) shift; cmd_edit "$@" ;;
|
||||
*) cmd_current "$@" ;;
|
||||
esac
|
||||
exit 0
|
41
bin/hosts
41
bin/hosts
|
@ -1,41 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Path to your hosts file
|
||||
hostsFile="/etc/hosts"
|
||||
|
||||
# Default IP address for host
|
||||
ip="127.0.0.1"
|
||||
|
||||
# Hostname to add/remove.
|
||||
hostname="$2"
|
||||
|
||||
yell() { echo "$0: $*" >&2; }
|
||||
die() { yell "$*"; exit 111; }
|
||||
try() { "$@" || die "cannot $*"; }
|
||||
|
||||
remove() {
|
||||
if [ -n "$(grep -P "[[:space:]]$hostname" /etc/hosts)" ]; then
|
||||
echo "$hostname found in $hostsFile. Removing now...";
|
||||
try sudo sed -ie "/[[:space:]]$hostname/d" "$hostsFile";
|
||||
else
|
||||
yell "$hostname was not found in $hostsFile";
|
||||
fi
|
||||
}
|
||||
|
||||
add() {
|
||||
if [ -n "$(grep -P "[[:space:]]$hostname" /etc/hosts)" ]; then
|
||||
yell "$hostname, already exists: $(grep $hostname $hostsFile)";
|
||||
else
|
||||
echo "Adding $hostname to $hostsFile...";
|
||||
try printf "%s\t%s\n" "$ip" "$hostname" | sudo tee -a "$hostsFile" > /dev/null;
|
||||
|
||||
if [ -n "$(grep $hostname /etc/hosts)" ]; then
|
||||
echo "$hostname was added succesfully:";
|
||||
echo "$(grep $hostname /etc/hosts)";
|
||||
else
|
||||
die "Failed to add $hostname";
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
$@
|
133
bin/is
133
bin/is
|
@ -1,133 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) 2016 Józef Sokołowski
|
||||
# Distributed under the MIT License
|
||||
#
|
||||
# For most current version checkout repository:
|
||||
# https://github.com/qzb/is.sh
|
||||
#
|
||||
|
||||
is() {
|
||||
if [ "$1" == "--help" ]; then
|
||||
cat << EOF
|
||||
Conditions:
|
||||
is equal VALUE_A VALUE_B
|
||||
is matching REGEXP VALUE
|
||||
is substring VALUE_A VALUE_B
|
||||
is empty VALUE
|
||||
is number VALUE
|
||||
is gt NUMBER_A NUMBER_B
|
||||
is lt NUMBER_A NUMBER_B
|
||||
is ge NUMBER_A NUMBER_B
|
||||
is le NUMBER_A NUMBER_B
|
||||
is file PATH
|
||||
is dir PATH
|
||||
is link PATH
|
||||
is existing PATH
|
||||
is readable PATH
|
||||
is writeable PATH
|
||||
is executable PATH
|
||||
is available COMMAND
|
||||
is older PATH_A PATH_B
|
||||
is newer PATH_A PATH_B
|
||||
is true VALUE
|
||||
is false VALUE
|
||||
|
||||
Negation:
|
||||
is not equal VALUE_A VALUE_B
|
||||
|
||||
Optional article:
|
||||
is not a number VALUE
|
||||
is an existing PATH
|
||||
is the file PATH
|
||||
EOF
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$1" == "--version" ]; then
|
||||
echo "is.sh 1.1.0"
|
||||
exit
|
||||
fi
|
||||
|
||||
local condition="$1"
|
||||
local value_a="$2"
|
||||
local value_b="$3"
|
||||
|
||||
if [ "$condition" == "not" ]; then
|
||||
shift 1
|
||||
! is "${@}"
|
||||
return $?
|
||||
fi
|
||||
|
||||
if [ "$condition" == "a" ] || [ "$condition" == "an" ] || [ "$condition" == "the" ]; then
|
||||
shift 1
|
||||
is "${@}"
|
||||
return $?
|
||||
fi
|
||||
|
||||
case "$condition" in
|
||||
file)
|
||||
[ -f "$value_a" ]; return $?;;
|
||||
dir|directory)
|
||||
[ -d "$value_a" ]; return $?;;
|
||||
link|symlink)
|
||||
[ -L "$value_a" ]; return $?;;
|
||||
existent|existing|exist|exists)
|
||||
[ -e "$value_a" ]; return $?;;
|
||||
readable)
|
||||
[ -r "$value_a" ]; return $?;;
|
||||
writeable)
|
||||
[ -w "$value_a" ]; return $?;;
|
||||
executable)
|
||||
[ -x "$value_a" ]; return $?;;
|
||||
available|installed)
|
||||
which "$value_a"; return $?;;
|
||||
empty)
|
||||
[ -z "$value_a" ]; return $?;;
|
||||
number)
|
||||
echo "$value_a" | grep -E '^[0-9]+(\.[0-9]+)?$'; return $?;;
|
||||
older)
|
||||
[ "$value_a" -ot "$value_b" ]; return $?;;
|
||||
newer)
|
||||
[ "$value_a" -nt "$value_b" ]; return $?;;
|
||||
gt)
|
||||
is not a number "$value_a" && return 1;
|
||||
is not a number "$value_b" && return 1;
|
||||
awk "BEGIN {exit $value_a > $value_b ? 0 : 1}"; return $?;;
|
||||
lt)
|
||||
is not a number "$value_a" && return 1;
|
||||
is not a number "$value_b" && return 1;
|
||||
awk "BEGIN {exit $value_a < $value_b ? 0 : 1}"; return $?;;
|
||||
ge)
|
||||
is not a number "$value_a" && return 1;
|
||||
is not a number "$value_b" && return 1;
|
||||
awk "BEGIN {exit $value_a >= $value_b ? 0 : 1}"; return $?;;
|
||||
le)
|
||||
is not a number "$value_a" && return 1;
|
||||
is not a number "$value_b" && return 1;
|
||||
awk "BEGIN {exit $value_a <= $value_b ? 0 : 1}"; return $?;;
|
||||
eq|equal)
|
||||
[ "$value_a" = "$value_b" ] && return 0;
|
||||
is not a number "$value_a" && return 1;
|
||||
is not a number "$value_b" && return 1;
|
||||
awk "BEGIN {exit $value_a == $value_b ? 0 : 1}"; return $?;;
|
||||
match|matching)
|
||||
echo "$value_b" | grep -xE "$value_a"; return $?;;
|
||||
substr|substring)
|
||||
echo "$value_b" | grep -F "$value_a"; return $?;;
|
||||
true)
|
||||
[ "$value_a" == true ] || [ "$value_a" == 0 ]; return $?;;
|
||||
false)
|
||||
[ "$value_a" != true ] && [ "$value_a" != 0 ]; return $?;;
|
||||
esac > /dev/null
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
if is not equal "${BASH_SOURCE[0]}" "$0"; then
|
||||
export -f is
|
||||
else
|
||||
is "${@}"
|
||||
exit $?
|
||||
fi
|
||||
|
156
bin/lj
156
bin/lj
|
@ -1,156 +0,0 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
# Create a mapping of log levels to their names
|
||||
typeset -A _log_levels
|
||||
_log_levels=(
|
||||
'emergency' 0
|
||||
'alert' 1
|
||||
'critical' 2
|
||||
'error' 3
|
||||
'warning' 4
|
||||
'notice' 5
|
||||
'info' 6
|
||||
'debug' 7
|
||||
)
|
||||
|
||||
###
|
||||
# Output usage information and exit
|
||||
###
|
||||
function _lumberjack_usage() {
|
||||
echo "\033[0;33mUsage:\033[0;m"
|
||||
echo " lj [options] [<level>] <message>"
|
||||
echo
|
||||
echo "\033[0;33mOptions:\033[0;m"
|
||||
echo " -h, --help Output help text and exit"
|
||||
echo " -v, --version Output version information and exit"
|
||||
echo " -f, --file Set the logfile and exit"
|
||||
echo " -l, --level Set the log level and exit"
|
||||
echo
|
||||
echo "\033[0;33mLevels:\033[0;m"
|
||||
echo " emergency"
|
||||
echo " alert"
|
||||
echo " critical"
|
||||
echo " error"
|
||||
echo " warning"
|
||||
echo " notice"
|
||||
echo " info"
|
||||
echo " debug"
|
||||
}
|
||||
|
||||
###
|
||||
# Output the message to the logfile
|
||||
###
|
||||
function _lumberjack_message() {
|
||||
local level="$1" file="$2" logtype="$3" msg="${(@)@:4}"
|
||||
|
||||
# If the file string is empty, output an error message
|
||||
if [[ -z $file ]]; then
|
||||
echo "\033[0;31mNo logfile has been set for this process. Use \`lumberjack --file /path/to/file\` to set it\033[0;m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If the level is not set, assume 5 (notice)
|
||||
if [[ -z $level ]]; then
|
||||
level=5
|
||||
fi
|
||||
|
||||
case $logtype in
|
||||
# If a valid logtype is passed
|
||||
emergency|alert|critical|error|warning|notice|info|debug )
|
||||
# We do nothing here
|
||||
;;
|
||||
# In all other cases
|
||||
* )
|
||||
# Second argument was not a log level, so manually set it to notice
|
||||
# and include the first parameter in the message
|
||||
logtype='notice'
|
||||
msg="${(@)@:3}"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $_log_levels[$logtype] > $level ]]; then
|
||||
# The message being recorded is for a higher log level than the one
|
||||
# currently being recorded, so gracefully exit
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Output the message to the logfile
|
||||
echo "[$(echo $logtype | tr '[a-z]' '[A-Z]')] [$(date '+%Y-%m-%d %H:%M:%S')] $msg" >> $file
|
||||
}
|
||||
|
||||
###
|
||||
# The main lumberjack process
|
||||
###
|
||||
function _lumberjack() {
|
||||
local help version logfile loglevel dir statefile state
|
||||
|
||||
# Create the state directory if it doesn't exist
|
||||
dir="${ZDOTDIR:-$HOME}/.lumberjack"
|
||||
if [[ ! -d $dir ]]; then
|
||||
mkdir -p $dir
|
||||
fi
|
||||
|
||||
# If a statefile already exists, load the level and file
|
||||
statefile="$dir/$PPID"
|
||||
if [[ -f $statefile ]]; then
|
||||
state=$(cat $statefile)
|
||||
level="$state[1]"
|
||||
file="${(@)state:2}"
|
||||
fi
|
||||
|
||||
# Parse CLI options
|
||||
zparseopts -D h=help -help=help \
|
||||
v=version -version=version \
|
||||
f:=logfile -file:=logfile \
|
||||
l:=loglevel -level:=loglevel
|
||||
|
||||
# If the help option is passed, output usage information and exit
|
||||
if [[ -n $help ]]; then
|
||||
_lumberjack_usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# If the version option is passed, output the version and exit
|
||||
if [[ -n $version ]]; then
|
||||
echo "0.1.1"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# If the logfile option is passed, set the current logfile
|
||||
# for the parent process ID
|
||||
if [[ -n $logfile ]]; then
|
||||
shift logfile
|
||||
file=$logfile
|
||||
|
||||
# Create the log file if it doesn't exist
|
||||
if [[ ! -f $file ]]; then
|
||||
touch $file
|
||||
fi
|
||||
fi
|
||||
|
||||
# If the loglevel option is passed, set the current loglevel
|
||||
# for the parent process ID
|
||||
if [[ -n $loglevel ]]; then
|
||||
shift loglevel
|
||||
level=$_log_levels[$loglevel]
|
||||
fi
|
||||
|
||||
if [[ -z $level ]]; then
|
||||
level=5
|
||||
fi
|
||||
|
||||
# Check if we're setting options rather than logging
|
||||
if [[ -n $logfile || -n $loglevel ]]; then
|
||||
# Store the state
|
||||
echo "$level $file" >! $statefile
|
||||
|
||||
# Exit gracefully
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Log the message
|
||||
_lumberjack_message "$level" "$file" "$@"
|
||||
}
|
||||
|
||||
_lumberjack "$@"
|
||||
|
21
bin/notify
21
bin/notify
|
@ -1,21 +0,0 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
$script = array_shift($_SERVER['argv']);
|
||||
$settings['token'] = 'ayndqf6fdyjo9pua8reusvvb733k1u';
|
||||
$settings['user'] = 'uesmxehx2bcuyv5prfrw39ema2312f';
|
||||
$settings['title'] = array_shift($_SERVER['argv']);
|
||||
$settings['message'] = array_shift($_SERVER['argv']);
|
||||
$settings['priority'] = 1;
|
||||
|
||||
$curl = curl_init("https://api.pushover.net/1/messages.json");
|
||||
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $settings);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$return = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
$json = json_decode($return, true);
|
||||
|
||||
if(isset($json['info'])) echo("Result: ${json['info']}");
|
318
bin/revolver
318
bin/revolver
|
@ -1,318 +0,0 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
local -A _revolver_spinners
|
||||
_revolver_spinners=(
|
||||
'dots' '0.08 ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏'
|
||||
'dots2' '0.08 ⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷'
|
||||
'dots3' '0.08 ⠋ ⠙ ⠚ ⠞ ⠖ ⠦ ⠴ ⠲ ⠳ ⠓'
|
||||
'dots4' '0.08 ⠄ ⠆ ⠇ ⠋ ⠙ ⠸ ⠰ ⠠ ⠰ ⠸ ⠙ ⠋ ⠇ ⠆'
|
||||
'dots5' '0.08 ⠋ ⠙ ⠚ ⠒ ⠂ ⠂ ⠒ ⠲ ⠴ ⠦ ⠖ ⠒ ⠐ ⠐ ⠒ ⠓ ⠋'
|
||||
'dots6' '0.08 ⠁ ⠉ ⠙ ⠚ ⠒ ⠂ ⠂ ⠒ ⠲ ⠴ ⠤ ⠄ ⠄ ⠤ ⠴ ⠲ ⠒ ⠂ ⠂ ⠒ ⠚ ⠙ ⠉ ⠁'
|
||||
'dots7' '0.08 ⠈ ⠉ ⠋ ⠓ ⠒ ⠐ ⠐ ⠒ ⠖ ⠦ ⠤ ⠠ ⠠ ⠤ ⠦ ⠖ ⠒ ⠐ ⠐ ⠒ ⠓ ⠋ ⠉ ⠈'
|
||||
'dots8' '0.08 ⠁ ⠁ ⠉ ⠙ ⠚ ⠒ ⠂ ⠂ ⠒ ⠲ ⠴ ⠤ ⠄ ⠄ ⠤ ⠠ ⠠ ⠤ ⠦ ⠖ ⠒ ⠐ ⠐ ⠒ ⠓ ⠋ ⠉ ⠈ ⠈'
|
||||
'dots9' '0.08 ⢹ ⢺ ⢼ ⣸ ⣇ ⡧ ⡗ ⡏'
|
||||
'dots10' '0.08 ⢄ ⢂ ⢁ ⡁ ⡈ ⡐ ⡠'
|
||||
'dots11' '0.1 ⠁ ⠂ ⠄ ⡀ ⢀ ⠠ ⠐ ⠈'
|
||||
'dots12' '0.08 "⢀⠀" "⡀⠀" "⠄⠀" "⢂⠀" "⡂⠀" "⠅⠀" "⢃⠀" "⡃⠀" "⠍⠀" "⢋⠀" "⡋⠀" "⠍⠁" "⢋⠁" "⡋⠁" "⠍⠉" "⠋⠉" "⠋⠉" "⠉⠙" "⠉⠙" "⠉⠩" "⠈⢙" "⠈⡙" "⢈⠩" "⡀⢙" "⠄⡙" "⢂⠩" "⡂⢘" "⠅⡘" "⢃⠨" "⡃⢐" "⠍⡐" "⢋⠠" "⡋⢀" "⠍⡁" "⢋⠁" "⡋⠁" "⠍⠉" "⠋⠉" "⠋⠉" "⠉⠙" "⠉⠙" "⠉⠩" "⠈⢙" "⠈⡙" "⠈⠩" "⠀⢙" "⠀⡙" "⠀⠩" "⠀⢘" "⠀⡘" "⠀⠨" "⠀⢐" "⠀⡐" "⠀⠠" "⠀⢀" "⠀⡀"'
|
||||
'line' '0.13 - \\ | /'
|
||||
'line2' '0.1 ⠂ - – — – -'
|
||||
'pipe' '0.1 ┤ ┘ ┴ └ ├ ┌ ┬ ┐'
|
||||
'simpleDots' '0.4 ". " ".. " "..." " "'
|
||||
'simpleDotsScrolling' '0.2 ". " ".. " "..." " .." " ." " "'
|
||||
'star' '0.07 ✶ ✸ ✹ ✺ ✹ ✷'
|
||||
'star2' '0.08 + x *'
|
||||
'flip' "0.07 _ _ _ - \` \` ' ´ - _ _ _"
|
||||
'hamburger' '0.1 ☱ ☲ ☴'
|
||||
'growVertical' '0.12 ▁ ▃ ▄ ▅ ▆ ▇ ▆ ▅ ▄ ▃'
|
||||
'growHorizontal' '0.12 ▏ ▎ ▍ ▌ ▋ ▊ ▉ ▊ ▋ ▌ ▍ ▎'
|
||||
'balloon' '0.14 " " "." "o" "O" "@" "*" " "'
|
||||
'balloon2' '0.12 . o O ° O o .'
|
||||
'noise' '0.14 ▓ ▒ ░'
|
||||
'bounce' '0.1 ⠁ ⠂ ⠄ ⠂'
|
||||
'boxBounce' '0.12 ▖ ▘ ▝ ▗'
|
||||
'boxBounce2' '0.1 ▌ ▀ ▐ ▄'
|
||||
'triangle' '0.05 ◢ ◣ ◤ ◥'
|
||||
'arc' '0.1 ◜ ◠ ◝ ◞ ◡ ◟'
|
||||
'circle' '0.12 ◡ ⊙ ◠'
|
||||
'squareCorners' '0.18 ◰ ◳ ◲ ◱'
|
||||
'circleQuarters' '0.12 ◴ ◷ ◶ ◵'
|
||||
'circleHalves' '0.05 ◐ ◓ ◑ ◒'
|
||||
'squish' '0.1 ╫ ╪'
|
||||
'toggle' '0.25 ⊶ ⊷'
|
||||
'toggle2' '0.08 ▫ ▪'
|
||||
'toggle3' '0.12 □ ■'
|
||||
'toggle4' '0.1 ■ □ ▪ ▫'
|
||||
'toggle5' '0.1 ▮ ▯'
|
||||
'toggle6' '0.3 ဝ ၀'
|
||||
'toggle7' '0.08 ⦾ ⦿'
|
||||
'toggle8' '0.1 ◍ ◌'
|
||||
'toggle9' '0.1 ◉ ◎'
|
||||
'toggle10' '0.1 ㊂ ㊀ ㊁'
|
||||
'toggle11' '0.05 ⧇ ⧆'
|
||||
'toggle12' '0.12 ☗ ☖'
|
||||
'toggle13' '0.08 = * -'
|
||||
'arrow' '0.1 ← ↖ ↑ ↗ → ↘ ↓ ↙'
|
||||
'arrow2' '0.12 ▹▹▹▹▹ ▸▹▹▹▹ ▹▸▹▹▹ ▹▹▸▹▹ ▹▹▹▸▹ ▹▹▹▹▸'
|
||||
'bouncingBar' '0.08 "[ ]" "[ =]" "[ ==]" "[ ===]" "[====]" "[=== ]" "[== ]" "[= ]"'
|
||||
'bouncingBall' '0.08 "( ● )" "( ● )" "( ● )" "( ● )" "( ●)" "( ● )" "( ● )" "( ● )" "( ● )" "(● )"'
|
||||
'pong' '0.08 "▐⠂ ▌" "▐⠈ ▌" "▐ ⠂ ▌" "▐ ⠠ ▌" "▐ ⡀ ▌" "▐ ⠠ ▌" "▐ ⠂ ▌" "▐ ⠈ ▌" "▐ ⠂ ▌" "▐ ⠠ ▌" "▐ ⡀ ▌" "▐ ⠠ ▌" "▐ ⠂ ▌" "▐ ⠈ ▌" "▐ ⠂▌" "▐ ⠠▌" "▐ ⡀▌" "▐ ⠠ ▌" "▐ ⠂ ▌" "▐ ⠈ ▌" "▐ ⠂ ▌" "▐ ⠠ ▌" "▐ ⡀ ▌" "▐ ⠠ ▌" "▐ ⠂ ▌" "▐ ⠈ ▌" "▐ ⠂ ▌" "▐ ⠠ ▌" "▐ ⡀ ▌" "▐⠠ ▌"'
|
||||
'shark' '0.12 "▐|\\____________▌" "▐_|\\___________▌" "▐__|\\__________▌" "▐___|\\_________▌" "▐____|\\________▌" "▐_____|\\_______▌" "▐______|\\______▌" "▐_______|\\_____▌" "▐________|\\____▌" "▐_________|\\___▌" "▐__________|\\__▌" "▐___________|\\_▌" "▐____________|\\▌" "▐____________/|▌" "▐___________/|_▌" "▐__________/|__▌" "▐_________/|___▌" "▐________/|____▌" "▐_______/|_____▌" "▐______/|______▌" "▐_____/|_______▌" "▐____/|________▌" "▐___/|_________▌" "▐__/|__________▌" "▐_/|___________▌" "▐/|____________▌"'
|
||||
)
|
||||
|
||||
###
|
||||
# Output usage information and exit
|
||||
###
|
||||
function _revolver_usage() {
|
||||
echo "\033[0;33mUsage:\033[0;m"
|
||||
echo " revolver [options] <command> <message>"
|
||||
echo
|
||||
echo "\033[0;33mOptions:\033[0;m"
|
||||
echo " -h, --help Output help text and exit"
|
||||
echo " -v, --version Output version information and exit"
|
||||
echo " -s, --style Set the spinner style"
|
||||
echo
|
||||
echo "\033[0;33mCommands:\033[0;m"
|
||||
echo " start <message> Start the spinner"
|
||||
echo " update <message> Update the message"
|
||||
echo " stop Stop the spinner"
|
||||
echo " demo Display an demo of each style"
|
||||
}
|
||||
|
||||
###
|
||||
# The main revolver process, which contains the loop
|
||||
###
|
||||
function _revolver_process() {
|
||||
local dir statefile state msg pid="$1" spinner_index=0
|
||||
|
||||
# Find the directory and load the statefile
|
||||
dir=${REVOLVER_DIR:-"${ZDOTDIR:-$HOME}/.revolver"}
|
||||
statefile="$dir/$pid"
|
||||
|
||||
# The frames that, when animated, will make up
|
||||
# our spinning indicator
|
||||
frames=(${(@z)_revolver_spinners[$style]})
|
||||
interval=${(@z)frames[1]}
|
||||
shift frames
|
||||
|
||||
# Create a never-ending loop
|
||||
while [[ 1 -eq 1 ]]; do
|
||||
# If the statefile has been removed, exit the script
|
||||
# to prevent it from being orphaned
|
||||
if [[ ! -f $statefile ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for the existence of the parent process
|
||||
$(kill -s 0 $pid 2&>/dev/null)
|
||||
|
||||
# If process doesn't exist, exit the script
|
||||
# to prevent it from being orphaned
|
||||
if [[ $? -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Load the current state, and parse it to get
|
||||
# the message to be displayed
|
||||
state=($(cat $statefile))
|
||||
|
||||
msg="${(@)state:1}"
|
||||
|
||||
# Output the current spinner frame, and add a
|
||||
# slight delay before the next one
|
||||
_revolver_spin
|
||||
sleep ${interval:-"0.1"}
|
||||
done
|
||||
}
|
||||
|
||||
###
|
||||
# Output the spinner itself, along with a message
|
||||
###
|
||||
function _revolver_spin() {
|
||||
local dir statefile state pid frame
|
||||
|
||||
# ZSH arrays start at 1, so we need to bump the index if it's 0
|
||||
if [[ $spinner_index -eq 0 ]]; then
|
||||
spinner_index+=1
|
||||
fi
|
||||
|
||||
# Calculate the screen width
|
||||
lim=$(tput cols)
|
||||
|
||||
# Clear the line and move the cursor to the start
|
||||
printf ' %.0s' {1..$lim}
|
||||
echo -n "\r"
|
||||
|
||||
# Echo the current frame and message, and overwrite
|
||||
# the rest of the line with white space
|
||||
msg="\033[0;38;5;242m${msg}\033[0;m"
|
||||
frame="${${(@z)frames}[$spinner_index]//\"}"
|
||||
printf '%*.*b' ${#msg} $lim "$frame $msg$(printf '%0.1s' " "{1..$lim})"
|
||||
|
||||
# Return to the beginning of the line
|
||||
echo -n "\r"
|
||||
|
||||
# Set the spinner index to the next frame
|
||||
spinner_index=$(( $(( $spinner_index + 1 )) % $(( ${#frames} + 1 )) ))
|
||||
}
|
||||
|
||||
###
|
||||
# Stop the current spinner process
|
||||
###
|
||||
function _revolver_stop() {
|
||||
local dir statefile state pid
|
||||
|
||||
# Find the directory and load the statefile
|
||||
dir=${REVOLVER_DIR:-"${ZDOTDIR:-$HOME}/.revolver"}
|
||||
statefile="$dir/$PPID"
|
||||
|
||||
# If the statefile does not exist, raise an error.
|
||||
# The spinner process itself performs the same check
|
||||
# and kills itself, so it should never be orphaned
|
||||
if [[ ! -f $statefile ]]; then
|
||||
echo '\033[0;31mRevolver process could not be found\033[0;m'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the current state, and parse it to find the PID
|
||||
# of the spinner process
|
||||
state=($(cat $statefile))
|
||||
pid="$state[1]"
|
||||
|
||||
# Clear the line and move the cursor to the start
|
||||
printf ' %.0s' {1..$(tput cols)}
|
||||
echo -n "\r"
|
||||
|
||||
# If a PID has been found, kill the process
|
||||
[[ ! -z $pid ]] && kill "$pid" > /dev/null
|
||||
unset pid
|
||||
|
||||
# Remove the statefile
|
||||
rm $statefile
|
||||
}
|
||||
|
||||
###
|
||||
# Update the message being displayed
|
||||
function _revolver_update() {
|
||||
local dir statefile state pid msg="$1"
|
||||
|
||||
# Find the directory and load the statefile
|
||||
dir=${REVOLVER_DIR:-"${ZDOTDIR:-$HOME}/.revolver"}
|
||||
statefile="$dir/$PPID"
|
||||
|
||||
# If the statefile does not exist, raise an error.
|
||||
# The spinner process itself performs the same check
|
||||
# and kills itself, so it should never be orphaned
|
||||
if [[ ! -f $statefile ]]; then
|
||||
echo '\033[0;31mRevolver process could not be found\033[0;m'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the current state, and parse it to find the PID
|
||||
# of the spinner process
|
||||
state=($(cat $statefile))
|
||||
pid="$state[1]"
|
||||
|
||||
# Clear the line and move the cursor to the start
|
||||
printf ' %.0s' {1..$(tput cols)}
|
||||
echo -n "\r"
|
||||
|
||||
# Echo the new message to the statefile, to be
|
||||
# picked up by the spinner process
|
||||
echo "$pid $msg" >! $statefile
|
||||
}
|
||||
|
||||
###
|
||||
# Create a new spinner with the specified message
|
||||
###
|
||||
function _revolver_start() {
|
||||
local dir statefile msg="$1"
|
||||
|
||||
# Find the directory and create it if it doesn't exist
|
||||
dir=${REVOLVER_DIR:-"${ZDOTDIR:-$HOME}/.revolver"}
|
||||
if [[ ! -d $dir ]]; then
|
||||
mkdir -p $dir
|
||||
fi
|
||||
|
||||
# Create the filename for the statefile
|
||||
statefile="$dir/$PPID"
|
||||
|
||||
touch $statefile
|
||||
if [[ ! -f $statefile ]]; then
|
||||
echo '\033[0;31mRevolver process could not create state file\033[0;m'
|
||||
echo "Check that the directory $dir is writable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Start the spinner process in the background
|
||||
_revolver_process $PPID &!
|
||||
|
||||
# Save the current state to the statefile
|
||||
echo "$! $msg" >! $statefile
|
||||
}
|
||||
|
||||
###
|
||||
# Demonstrate each of the included spinner styles
|
||||
###
|
||||
function _revolver_demo() {
|
||||
for style in "${(@k)_revolver_spinners[@]}"; do
|
||||
revolver --style $style start $style
|
||||
sleep 2
|
||||
revolver stop
|
||||
done
|
||||
}
|
||||
|
||||
###
|
||||
# Handle command input
|
||||
###
|
||||
function _revolver() {
|
||||
# Get the context from the first parameter
|
||||
local help version style ctx="$1"
|
||||
|
||||
# Parse CLI options
|
||||
zparseopts -D \
|
||||
h=help -help=help \
|
||||
v=version -version=version \
|
||||
s:=style -style:=style
|
||||
|
||||
# Output usage information and exit
|
||||
if [[ -n $help ]]; then
|
||||
_revolver_usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Output version information and exit
|
||||
if [[ -n $version ]]; then
|
||||
echo '0.2.0'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -z $style ]]; then
|
||||
style='dots'
|
||||
fi
|
||||
|
||||
if [[ -n $style ]]; then
|
||||
shift style
|
||||
ctx="$1"
|
||||
fi
|
||||
|
||||
if [[ -z $_revolver_spinners[$style] ]]; then
|
||||
echo $(color red "Spinner '$style' is not recognised")
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $ctx in
|
||||
start|update|stop|demo)
|
||||
# Check if a valid command is passed,
|
||||
# and if so, run it
|
||||
_revolver_${ctx} "${(@)@:2}"
|
||||
;;
|
||||
*)
|
||||
# If the context is not recognised,
|
||||
# throw an error and exit
|
||||
echo "Command $ctx is not recognised"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_revolver "$@"
|
688
bin/shml
688
bin/shml
|
@ -1,688 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#SHML:START
|
||||
#************************************************#
|
||||
# SHML - Shell Markup Language Framework
|
||||
# v1.1.0
|
||||
# (MIT)
|
||||
# by Justin Dorfman - @jdorfman
|
||||
# && Joshua Mervine - @mervinej
|
||||
#
|
||||
# http://shml.xyz
|
||||
#************************************************#
|
||||
SHML_VERSION="1.1.0"
|
||||
|
||||
# Progress Bar
|
||||
##
|
||||
# options:
|
||||
# SHML_PROGRESS_CHAR - width of progress bar, default '#'
|
||||
# SHML_PROGRESS_WIDTH - width of progress bar, default 60
|
||||
# SHML_PROGRESS_MAX - maximum progress value, default 100
|
||||
# SHML_PROGRESS_BREAK - put a new line at the end of the output, default 'true'
|
||||
# SHML_PROGRESS_CLEAR - clear line at the end of the output, default 'false'
|
||||
# SHML_PGOGRESS_NOCURSOR - hide the cursor, default 'true'
|
||||
|
||||
progress() {
|
||||
[[ -z $SHML_PROGRESS_WIDTH ]] && SHML_PROGRESS_WIDTH=60
|
||||
[[ -z $SHML_PROGRESS_BREAK ]] && SHML_PROGRESS_BREAK=true
|
||||
[[ -z $SHML_PROGRESS_CLEAR ]] && SHML_PROGRESS_CLEAR=false
|
||||
[[ -z $SHML_PROGRESS_NOCURSOR ]] && SHML_PROGRESS_NOCURSOR=true
|
||||
# defaults
|
||||
local __title="Progress"
|
||||
local __steps=10
|
||||
local __char="#"
|
||||
|
||||
# arg parser
|
||||
[[ ! -z $1 ]] && __title=$1
|
||||
[[ ! -z $2 ]] && __steps=$2
|
||||
[[ ! -z $3 ]] && __char="$3"
|
||||
|
||||
local __width=${SHML_PROGRESS_WIDTH}
|
||||
local __break=${SHML_PROGRESS_BREAK}
|
||||
local __clear=${SHML_PROGRESS_CLEAR}
|
||||
local __ncursor=${SHML_PROGRESS_NOCURSOR}
|
||||
local __pct=0
|
||||
local __num=0
|
||||
local __len=0
|
||||
local __bar=''
|
||||
local __line=''
|
||||
|
||||
# ensure terminal
|
||||
[[ -t 1 ]] || return 1
|
||||
|
||||
# ensure tput
|
||||
if test "$(which tput)"; then
|
||||
if $__ncursor; then
|
||||
# hide cursor
|
||||
tput civis
|
||||
trap 'tput cnorm; exit 1' SIGINT
|
||||
fi
|
||||
fi
|
||||
|
||||
while read __value; do
|
||||
# compute pct
|
||||
__pct=$(( __value * 100 / __steps ))
|
||||
|
||||
# compute number of blocks to display
|
||||
__num=$(( __value * __width / __steps ))
|
||||
|
||||
# create bar string
|
||||
if [ $__num -gt 0 ]; then
|
||||
__bar=$(printf "%0.s${__char}" $(seq 1 $__num))
|
||||
fi
|
||||
|
||||
__line=$(printf "%s [%-${__witdth}s] (%d%%)" "$__title" "$__bar" "$__pct")
|
||||
|
||||
# print bar
|
||||
echo -en "${__line}\r"
|
||||
done
|
||||
|
||||
# clear line if requested
|
||||
if $__clear; then
|
||||
__len=$(echo -en "$__line" | wc -c)
|
||||
printf "%$((__len + 1))s\r" " "
|
||||
fi
|
||||
|
||||
# new line if requested
|
||||
$__break && echo
|
||||
|
||||
# show cursor again
|
||||
test "$(which tput)" && $__ncursor && tput cnorm
|
||||
}
|
||||
|
||||
# Confirm / Dialog
|
||||
##
|
||||
__default_confirm_success_input="y Y yes Yes YES ok OK Ok okay Okay OKAY k K continue Continue CONTINUE proceed Proceed PROCEED success Success SUCCESS successful Successful SUCCESSFUL good Good GOOD"
|
||||
confirm() {
|
||||
[[ -z $1 ]] && return 127
|
||||
|
||||
[[ -z $SHML_CONFIRM_SUCCESS ]] && SHML_CONFIRM_SUCCESS=$__default_confirm_success_input
|
||||
|
||||
echo -ne "$1 "
|
||||
local found=false
|
||||
while read __input; do
|
||||
for str in $(echo $SHML_CONFIRM_SUCCESS); do
|
||||
[[ "$str" == "$__input" ]] && found=true
|
||||
done
|
||||
break
|
||||
done
|
||||
|
||||
if $found; then
|
||||
[[ ! -z $2 ]] && eval $2
|
||||
return 0
|
||||
else
|
||||
[[ ! -z $3 ]] && eval $3
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
dialog() {
|
||||
[[ -z $1 ]] && return 127
|
||||
[[ -z $2 ]] && return 127
|
||||
|
||||
echo -en "$1 "
|
||||
while read __input; do
|
||||
eval "$2 $__input"
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
# Foreground (Text)
|
||||
##
|
||||
fgcolor() {
|
||||
local __end='\033[39m'
|
||||
local __color=$__end # end by default
|
||||
case "$1" in
|
||||
end|off|reset) __color=$__end;;
|
||||
black|000000|000) __color='\033[30m';;
|
||||
red|F00BAF) __color='\033[31m';;
|
||||
green|00CD00) __color='\033[32m';;
|
||||
yellow|CDCD00) __color='\033[33m';;
|
||||
blue|0286fe) __color='\033[34m';;
|
||||
magenta|e100cc) __color='\033[35m';;
|
||||
cyan|00d3cf) __color='\033[36m';;
|
||||
gray|e4e4e4) __color='\033[90m';;
|
||||
darkgray|4c4c4c) __color='\033[91m';;
|
||||
lightgreen|00fe00) __color='\033[92m';;
|
||||
lightyellow|f8fe00) __color='\033[93m';;
|
||||
lightblue|3a80b5) __color='\033[94m';;
|
||||
lightmagenta|fe00fe) __color='\033[95m';;
|
||||
lightcyan|00fefe) __color='\033[96m';;
|
||||
white|ffffff|fff) __color='\033[97m';;
|
||||
esac
|
||||
if test "$2"; then
|
||||
echo -en "$__color$2$__end"
|
||||
else
|
||||
echo -en "$__color"
|
||||
fi
|
||||
}
|
||||
|
||||
# Backwards Compatibility
|
||||
color() {
|
||||
fgcolor "$@"
|
||||
}
|
||||
|
||||
# Aliases
|
||||
fgc() {
|
||||
fgcolor "$@"
|
||||
}
|
||||
|
||||
c() {
|
||||
fgcolor "$@"
|
||||
}
|
||||
|
||||
# Background
|
||||
##
|
||||
bgcolor() {
|
||||
local __end='\033[49m'
|
||||
local __color=$__end # end by default
|
||||
case "$1" in
|
||||
end|off|reset) __color=$__end;;
|
||||
black|000000|000) __color='\033[40m';;
|
||||
red|F00BAF) __color='\033[41m';;
|
||||
green|00CD00) __color='\033[42m';;
|
||||
yellow|CDCD00) __color='\033[43m';;
|
||||
blue|0286fe) __color='\033[44m';;
|
||||
magenta|e100cc) __color='\033[45m';;
|
||||
cyan|00d3cf) __color='\033[46m';;
|
||||
gray|e4e4e4) __color='\033[47m';;
|
||||
darkgray|4c4c4c) __color='\033[100m';;
|
||||
lightred) __color='\033[101m';;
|
||||
lightgreen|00fe00) __color='\033[102m';;
|
||||
lightyellow|f8fe00) __color='\033[103m';;
|
||||
lightblue|3a80b5) __color='\033[104m';;
|
||||
lightmagenta|fe00fe) __color='\033[105m';;
|
||||
lightcyan|00fefe) __color='\033[106m';;
|
||||
white|fffff|fff) __color='\033[107m';;
|
||||
esac
|
||||
|
||||
if test "$2"; then
|
||||
echo -en "$__color$2$__end"
|
||||
else
|
||||
echo -en "$__color"
|
||||
fi
|
||||
}
|
||||
|
||||
#Backwards Compatibility
|
||||
background() {
|
||||
bgcolor "$@"
|
||||
}
|
||||
|
||||
#Aliases
|
||||
bgc() {
|
||||
bgcolor "$@"
|
||||
}
|
||||
|
||||
bg() {
|
||||
bgcolor "$@"
|
||||
}
|
||||
|
||||
## Color Bar
|
||||
color-bar() {
|
||||
if test "$2"; then
|
||||
for i in "$@"; do
|
||||
echo -en "$(background "$i" " ")"
|
||||
done; echo
|
||||
else
|
||||
for i in {16..21}{21..16}; do
|
||||
echo -en "\033[48;5;${i}m \033[0m"
|
||||
done; echo
|
||||
fi
|
||||
}
|
||||
|
||||
#Alises
|
||||
cb() {
|
||||
color-bar "$@"
|
||||
}
|
||||
|
||||
bar() {
|
||||
color-bar "$@"
|
||||
}
|
||||
|
||||
## Attributes
|
||||
##
|
||||
attribute() {
|
||||
local __end='\033[0m'
|
||||
local __attr=$__end # end by default
|
||||
case "$1" in
|
||||
end|off|reset) __attr=$__end;;
|
||||
bold) __attr='\033[1m';;
|
||||
dim) __attr='\033[2m';;
|
||||
underline) __attr='\033[4m';;
|
||||
blink) __attr='\033[5m';;
|
||||
invert) __attr='\033[7m';;
|
||||
hidden) __attr='\033[8m';;
|
||||
esac
|
||||
if test "$2"; then
|
||||
echo -en "$__attr$2$__end"
|
||||
else
|
||||
echo -en "$__attr"
|
||||
fi
|
||||
}
|
||||
a() {
|
||||
attribute "$@"
|
||||
}
|
||||
|
||||
## Elements
|
||||
br() {
|
||||
echo -e "\n\r"
|
||||
}
|
||||
|
||||
tab() {
|
||||
echo -e "\t"
|
||||
}
|
||||
|
||||
indent() {
|
||||
local __len=4
|
||||
local __int='^[0-9]+$'
|
||||
if test "$1"; then
|
||||
if [[ $1 =~ $__int ]] ; then
|
||||
__len=$1
|
||||
fi
|
||||
fi
|
||||
while [ $__len -gt 0 ]; do
|
||||
echo -n " "
|
||||
__len=$(( $__len - 1 ))
|
||||
done
|
||||
}
|
||||
|
||||
i() {
|
||||
indent "$@"
|
||||
}
|
||||
|
||||
hr() {
|
||||
local __len=60
|
||||
local __char='-'
|
||||
local __int='^[0-9]+$'
|
||||
if ! test "$2"; then
|
||||
if [[ $1 =~ $__int ]] ; then
|
||||
__len=$1
|
||||
elif test "$1"; then
|
||||
__char=$1
|
||||
fi
|
||||
else
|
||||
__len=$2
|
||||
__char=$1
|
||||
fi
|
||||
while [ $__len -gt 0 ]; do
|
||||
echo -n "$__char"
|
||||
__len=$(( $__len - 1 ))
|
||||
done
|
||||
}
|
||||
|
||||
# Icons
|
||||
##
|
||||
icon() {
|
||||
local i='';
|
||||
case "$1" in
|
||||
check|checkmark) i='\xE2\x9C\x93';;
|
||||
X|x|xmark) i='\xE2\x9C\x98';;
|
||||
'<3'|heart) i='\xE2\x9D\xA4';;
|
||||
sun) i='\xE2\x98\x80';;
|
||||
'*'|star) i='\xE2\x98\x85';;
|
||||
darkstar) i='\xE2\x98\x86';;
|
||||
umbrella) i='\xE2\x98\x82';;
|
||||
flag) i='\xE2\x9A\x91';;
|
||||
snow|snowflake) i='\xE2\x9D\x84';;
|
||||
music) i='\xE2\x99\xAB';;
|
||||
scissors) i='\xE2\x9C\x82';;
|
||||
tm|trademark) i='\xE2\x84\xA2';;
|
||||
copyright) i='\xC2\xA9';;
|
||||
apple) i='\xEF\xA3\xBF';;
|
||||
skull|bones) i='\xE2\x98\xA0';;
|
||||
':-)'|':)'|smile|face) i='\xE2\x98\xBA';;
|
||||
esac
|
||||
echo -ne "$i";
|
||||
}
|
||||
|
||||
# Emojis
|
||||
##
|
||||
emoji() {
|
||||
local i=""
|
||||
case "$1" in
|
||||
1F603|smiley|'=)'|':-)'|':)') i='😃';;
|
||||
1F607|innocent|halo) i='😇';;
|
||||
1F602|joy|lol|laughing) i='😂';;
|
||||
1F61B|tongue|'=p'|'=P') i='😛';;
|
||||
1F60A|blush|'^^'|blushing) i='😊';;
|
||||
1F61F|worried|sadface|sad) i='😟';;
|
||||
1F622|cry|crying|tear) i='😢';;
|
||||
1F621|rage|redface) i='😡';;
|
||||
1F44B|wave|hello|goodbye) i='👋';;
|
||||
1F44C|ok_hand|perfect|okay|nice|ok) i='👌';;
|
||||
1F44D|thumbsup|+1|like) i='👍';;
|
||||
1F44E|thumbsdown|-1|no|dislike) i='👎';;
|
||||
1F63A|smiley_cat|happycat) i='😺';;
|
||||
1F431|cat|kitten|:3|kitty) i='🐱';;
|
||||
1F436|dog|puppy) i='🐶';;
|
||||
1F41D|bee|honeybee|bumblebee) i='🐝';;
|
||||
1F437|pig|pighead) i='🐷';;
|
||||
1F435|monkey_face|monkey) i='🐵';;
|
||||
1F42E|cow|happycow) i='🐮';;
|
||||
1F43C|panda_face|panda|shpanda) i='🐼';;
|
||||
1F363|sushi|raw|sashimi) i='🍣';;
|
||||
1F3E0|home|house) i='🏠';;
|
||||
1F453|eyeglasses|bifocals) i='👓';;
|
||||
1F6AC|smoking|smoke|cigarette) i='🚬';;
|
||||
1F525|fire|flame|hot|snapstreak) i='🔥';;
|
||||
1F4A9|hankey|poop|poo|shit) i='💩';;
|
||||
1F37A|beer|homebrew|brew) i='🍺';;
|
||||
1F36A|cookie|biscuit|chocolate) i='🍪';;
|
||||
1F512|lock|padlock|secure) i='🔒';;
|
||||
1F513|unlock|openpadlock) i='🔓';;
|
||||
2B50|star|yellowstar) i='⭐';;
|
||||
1F0CF|black_joker|joker|wild) i='🃏';;
|
||||
2705|white_check_mark|check) i='✅';;
|
||||
274C|x|cross|xmark) i='❌';;
|
||||
1F6BD|toilet|restroom|loo) i='🚽';;
|
||||
1F514|bell|ringer|ring) i='🔔';;
|
||||
1F50E|mag_right|search|magnify) i='🔎';;
|
||||
1F3AF|dart|bullseye|darts) i='🎯';;
|
||||
1F4B5|dollar|cash|cream) i='💵';;
|
||||
1F4AD|thought_balloon|thinking) i='💭';;
|
||||
1F340|four_leaf_clover|luck) i='🍀';;
|
||||
esac
|
||||
echo -ne "$i"
|
||||
}
|
||||
|
||||
function e {
|
||||
emoji "$@"
|
||||
}
|
||||
|
||||
#SHML:END
|
||||
|
||||
|
||||
# Usage / Examples
|
||||
##
|
||||
if [ "$0" = "$BASH_SOURCE" ]; then
|
||||
|
||||
if [[ $@ =~ .*-v.* ]]; then
|
||||
echo "shml version ${SHML_VERSION}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
I=2
|
||||
echo -e "
|
||||
$(color "lightblue")
|
||||
#$(hr "*" 48)#
|
||||
# SHML - Shell Markup Language Framework
|
||||
# v${SHML_VERSION}
|
||||
# (MIT)
|
||||
# by Justin Dorfman - @jdorfman
|
||||
# && Joshua Mervine - @mervinej
|
||||
#
|
||||
# https://maxcdn.github.io/shml/
|
||||
#$(hr "*" 48)#
|
||||
$(color "end")
|
||||
|
||||
$(a bold 'SHML Usage / Help')
|
||||
$(hr '=')
|
||||
|
||||
$(a bold 'Section 0: Sourcing')
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)When installed in path:
|
||||
$(i $I) source \$(which shml.sh)
|
||||
|
||||
$(i $I)When installed locally:
|
||||
$(i $I) source ./shml.sh
|
||||
|
||||
$(a bold 'Section 1: Foreground')
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)\$(color red \"foo bar\")
|
||||
$(i $I)$(color red "foo bar")
|
||||
|
||||
$(i $I)\$(color blue \"foo bar\")
|
||||
$(i $I)$(color blue "foo bar")
|
||||
|
||||
$(i $I)\$(fgcolor green)
|
||||
$(i $I) >>foo bar<<
|
||||
$(i $I) >>bah boo<<
|
||||
$(i $I)\$(fgcolor end)
|
||||
$(i $I)$(fgcolor green)
|
||||
$(i $I)>>foo bar<<
|
||||
$(i $I)>>bah boo<<
|
||||
$(i $I)$(fgcolor end)
|
||||
|
||||
$(i $I)Short Hand: $(a underline 'c')
|
||||
|
||||
$(i $I)\$(c red 'foo')
|
||||
|
||||
$(i $I)Argument list:
|
||||
|
||||
$(i $I)black, red, green, yellow, blue, magenta, cyan, gray,
|
||||
$(i $I)white, darkgray, lightgreen, lightyellow, lightblue,
|
||||
$(i $I)lightmagenta, lightcyan
|
||||
|
||||
$(i $I)Termination: end, off, reset
|
||||
|
||||
$(i $I)Default (no arg): end
|
||||
|
||||
|
||||
$(a bold 'Section 2: Background')
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)\$(bgcolor red \"foo bar\")
|
||||
$(i $I)$(background red "foo bar")
|
||||
|
||||
$(i $I)\$(background blue \"foo bar\")
|
||||
$(i $I)$(background blue "foo bar")
|
||||
|
||||
$(i $I)\$(background green)
|
||||
$(i $I)$(i $I)>>foo bar<<
|
||||
$(i $I)$(i $I)>>bah boo<<
|
||||
$(i $I)\$(background end)
|
||||
$(background green)
|
||||
$(i $I)>>foo bar<<
|
||||
$(i $I)>>bah boo<<
|
||||
$(background end)
|
||||
|
||||
$(i $I)Short Hand: $(a underline 'bg')
|
||||
|
||||
$(i $I)\$(bg red 'foo')
|
||||
|
||||
$(i $I)Argument list:
|
||||
|
||||
$(i $I)black, red, green, yellow, blue, magenta, cyan, gray,
|
||||
$(i $I)white, darkgray, lightred, lightgreen, lightyellow,
|
||||
$(i $I)lightblue, lightmagenta, lightcyan
|
||||
|
||||
$(i $I)Termination: end, off, reset
|
||||
|
||||
$(i $I)Default (no arg): end
|
||||
|
||||
|
||||
$(a bold 'Section 3: Attributes')
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)$(a bold "Attributes only work on vt100 compatible terminals.")
|
||||
|
||||
$(i $I)> Note:
|
||||
$(i $I)> $(a underline 'attribute end') turns off everything,
|
||||
$(i $I)> including foreground and background color.
|
||||
|
||||
$(i $I)\$(attribute bold \"foo bar\")
|
||||
$(i $I)$(attribute bold "foo bar")
|
||||
|
||||
$(i $I)\$(attribute underline \"foo bar\")
|
||||
$(i $I)$(attribute underline "foo bar")
|
||||
|
||||
$(i $I)\$(attribute blink \"foo bar\")
|
||||
$(i $I)$(attribute blink "foo bar")
|
||||
|
||||
$(i $I)\$(attribute invert \"foo bar\")
|
||||
$(i $I)$(attribute invert "foo bar")
|
||||
|
||||
$(i $I)\$(attribute dim)
|
||||
$(i $I)$(i $I)>>foo bar<<
|
||||
$(i $I)$(i $I)>>bah boo<<
|
||||
$(i $I)\$(attribute end)
|
||||
$(i $I)$(attribute dim)
|
||||
$(i $I)$(i $I)>>foo bar<<
|
||||
$(i $I)$(i $I)>>bah boo<<
|
||||
$(i $I)$(attribute end)
|
||||
|
||||
$(i $I)Short Hand: $(a underline 'a')
|
||||
|
||||
$(i $I)\$(a bold 'foo')
|
||||
|
||||
$(i $I)Argument list:
|
||||
|
||||
$(i $I)bold, dim, underline, blink, invert, hidden
|
||||
|
||||
$(i $I)Termination: end, off, reset
|
||||
|
||||
$(i $I)Default (no arg): end
|
||||
|
||||
|
||||
$(a bold 'Section 4: Elements')
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)foo\$(br)\$(tab)bar
|
||||
$(i $I)foo$(br)$(tab)bar
|
||||
$(i $I)
|
||||
$(i $I)foo\$(br)\$(indent)bar\$(br)\$(indent 6)boo
|
||||
$(i $I)foo$(br)$(indent)bar$(br)$(indent 6)boo
|
||||
$(i $I)
|
||||
$(i $I)> Note: short hand for $(a underline 'indent') is $(a underline 'i')
|
||||
$(i $I)
|
||||
$(i $I)\$(hr)
|
||||
$(i $I)$(hr)
|
||||
$(i $I)
|
||||
$(i $I)\$(hr 50)
|
||||
$(i $I)$(hr 50)
|
||||
$(i $I)
|
||||
$(i $I)\$(hr '~' 40)
|
||||
$(i $I)$(hr '~' 40)
|
||||
$(i $I)
|
||||
$(i $I)\$(hr '#' 30)
|
||||
$(i $I)$(hr '#' 30)
|
||||
|
||||
|
||||
$(a bold 'Section 5: Icons')
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)Icons
|
||||
$(i $I)$(hr '-' 10)
|
||||
|
||||
$(i $I)\$(icon check) \$(icon '<3') \$(icon '*') \$(icon ':)')
|
||||
|
||||
$(i $I)$(icon check) $(icon '<3') $(icon '*') $(icon 'smile')
|
||||
|
||||
$(i $I)Argument list:
|
||||
|
||||
$(i $I)check|checkmark, X|x|xmark, <3|heart, sun, *|star,
|
||||
$(i $I)darkstar, umbrella, flag, snow|snowflake, music,
|
||||
$(i $I)scissors, tm|trademark, copyright, apple,
|
||||
$(i $I):-)|:)|smile|face
|
||||
|
||||
|
||||
$(a bold 'Section 6: Emojis')
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)Couldn't peep it with a pair of \$(emoji bifocals)
|
||||
$(i $I)Couldn't peep it with a pair of $(emoji bifocals)
|
||||
$(i $I)
|
||||
$(i $I)I'm no \$(emoji joker) play me as a \$(emoji joker)
|
||||
$(i $I)I'm no $(emoji joker) play me as a $(emoji joker)
|
||||
$(i $I)
|
||||
$(i $I)\$(emoji bee) on you like a \$(emoji house) on \$(emoji fire), \$(emoji smoke) ya
|
||||
$(i $I)$(emoji bee) on you like a $(emoji house) on $(emoji fire), $(emoji smoke) ya
|
||||
$(i $I)
|
||||
$(i $I)$(a bold 'Each Emoji has 1 or more alias')
|
||||
$(i $I)
|
||||
$(i $I)\$(emoji smiley) \$(emoji 1F603) \$(emoji '=)') \$(emoji ':-)') \$(emoji ':)')
|
||||
$(i $I)$(emoji smiley) $(emoji 1F603) $(emoji '=)') $(emoji ':-)') $(emoji ':)')
|
||||
|
||||
$(a bold 'Section 7: Color Bar')
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)\$(color-bar)
|
||||
$(i $I)$(color-bar)
|
||||
$(i $I)
|
||||
$(i $I)\$(color-bar red green yellow blue magenta \\
|
||||
$(i $I)$(i 15)cyan lightgray darkgray lightred \\
|
||||
$(i $I)$(i 15)lightgreen lightyellow lightblue \\
|
||||
$(i $I)$(i 15)lightmagenta lightcyan)
|
||||
$(i $I)$(color-bar red green yellow blue magenta \
|
||||
cyan lightgray darkgray lightred \
|
||||
lightgreen lightyellow lightblue \
|
||||
lightmagenta lightcyan)
|
||||
|
||||
$(i $I)Short Hand: $(a underline 'bar')
|
||||
$(i $I)
|
||||
$(i $I)\$(bar black yellow black yellow black yellow)
|
||||
$(i $I)$(bar black yellow black yellow black yellow)
|
||||
|
||||
$(a bold "Section 8: $(color red "[EXPERIMENTAL]") Progress Bar")
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)Usage: progress [TITLE] [STEPS] [CHAR]
|
||||
|
||||
$(i $I) - 'title' defines the progress bar title
|
||||
$(i $I) - 'steps' defines the number of steps for the progress bar to act upon
|
||||
$(i $I) - 'char' defines the character to be displayed in the progress bar
|
||||
|
||||
$(i $I)Example:
|
||||
|
||||
$(i $I)echo "\$\(color green\)"
|
||||
$(i $I)for i in \$(seq 0 10); do echo \$i; sleep .25; done | progress
|
||||
$(i $I)echo "\$\(color end\)"
|
||||
|
||||
$(color green "$(i $I)Example [#################### ] (50%)")
|
||||
|
||||
$(i $I)'progress' supports overriding default values by setting the following variables:
|
||||
|
||||
$(i $I) - SHML_PROGRESS_WIDTH - width of progress bar, default 60
|
||||
$(i $I) - SHML_PROGRESS_BREAK - put a new line at the end of the output, default 'true'
|
||||
$(i $I) - SHML_PROGRESS_CLEAR - clear line at the end of the output, default 'false'
|
||||
$(i $I) - SHML_PGOGRESS_NOCURSOR - hide the cursor, default 'true'
|
||||
|
||||
$(i $I)NOTE: These variables $(a bold 'must') be defined before sourcing 'shml'!
|
||||
|
||||
$(a bold "Section 9: $(color red "[EXPERIMENTAL]") Confirm")
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)Ask a yes or no question and handle results.
|
||||
|
||||
$(i $I)Usage: confirm QUESTION [SUCCESS_FUNCTION] [FAILURE_FUNCTION]
|
||||
|
||||
$(i $I)Supports the following as affirmitive responses by default:
|
||||
|
||||
$(for r in `echo "$__default_confirm_success_input"`; do echo "$(i $I) - '$r'"; done)
|
||||
|
||||
$(i $I)Default affirmtive responses can be overwritten by setting 'SHML_CONFIRM_SUCCESS'.
|
||||
|
||||
$(i $I)Example:
|
||||
|
||||
$(i $I)function on_success() {
|
||||
$(i $I) echo \"yay\"
|
||||
$(i $I)}
|
||||
|
||||
$(i $I)function on_failure() {
|
||||
$(i $I) echo \"boo\"
|
||||
$(i $I)}
|
||||
|
||||
$(i $I)confirm \"CREAM?\" \"on_success\" \"on_failure\"
|
||||
|
||||
|
||||
$(a bold "Section 9: $(color red "[EXPERIMENTAL]") Dialog")
|
||||
$(hr '-')
|
||||
|
||||
$(i $I)Asks a question and passes the answer to a response handler function.
|
||||
|
||||
$(i $I)Usage: dialog QUESTION [RESPONSE_FUNCTION]
|
||||
|
||||
$(i $I)Example:
|
||||
|
||||
$(i $I)function on_response() {
|
||||
$(i $I) echo \"hello $1\"
|
||||
$(i $I)}
|
||||
|
||||
$(i $I)dialog \"What is your name?\" \"on_response\"
|
||||
|
||||
" | less -r
|
||||
fi
|
||||
|
||||
# vim: ft=sh:
|
Loading…
Add table
Add a link
Reference in a new issue