From 00fec9b61b59e8f214843e8d7a7947e28eaff663 Mon Sep 17 00:00:00 2001 From: Nikolas Weger Date: Fri, 5 Oct 2018 16:20:39 +0200 Subject: [PATCH] updated stuff --- bin/ansi | 1457 +++++++++++++++++++++++++++++++------- bin/desk | 3 +- bin/mo | 23 +- bin/nma | 11 - bin/revolver | 2 +- bin/shml | 314 ++++++-- cfg/ssh/cfg | 4 +- cfg/zsh/cfg.d/export.zsh | 6 +- cfg/zsh/cfg.d/ohmy.zsh | 1 + lib/completions | 2 +- lib/gitignore | 2 +- lib/has | 2 +- lib/ohmyzsh | 2 +- 13 files changed, 1484 insertions(+), 345 deletions(-) delete mode 100755 bin/nma diff --git a/bin/ansi b/bin/ansi index 242d955..6fedd26 100755 --- a/bin/ansi +++ b/bin/ansi @@ -6,104 +6,668 @@ # Licensed under the MIT license with an additional non-advertising clause # See http://github.com/fidian/ansi -ansi::addCode() { - local N +ANSI_ESC=$'\033' +ANSI_CSI="${ANSI_ESC}[" +ANSI_OSC="${ANSI_ESC}]" +ANSI_ST="${ANSI_ESC}\\" +ANSI_REPORT="" # The return value from ansi::report - if [[ "$1" == *=* ]]; then - N="${1#*=}" - N="${N//,/;}" - else - N="" - fi - - OUTPUT="$OUTPUT$CSI$N$2" +ansi::backward() { + printf '%s%sD' "$ANSI_CSI" "${1-}" } -ansi::addColor() { - OUTPUT="$OUTPUT$CSI${1}m" +ansi::bell() { + printf "%s" $'\007' +} - if [ ! -z "$2" ]; then - SUFFIX="$CSI${2}m$SUFFIX" - fi +ansi::black() { + printf '%s30m' "$ANSI_CSI" +} + +ansi::blackIntense() { + printf '%s90m' "$ANSI_CSI" +} + +ansi::blink() { + printf '%s5m' "$ANSI_CSI" +} + +ansi::blue() { + printf '%s34m' "$ANSI_CSI" +} + +ansi::blueIntense() { + printf '%s94m' "$ANSI_CSI" +} + +ansi::bgBlack() { + printf '%s40m' "$ANSI_CSI" +} + +ansi::bgBlackIntense() { + printf '%s100m' "$ANSI_CSI" +} + +ansi::bgBlue() { + printf '%s44m' "$ANSI_CSI" +} + +ansi::bgBlueIntense() { + printf '%s104m' "$ANSI_CSI" +} + +ansi::bgColor() { + printf '%s48;5;%sm' "$ANSI_CSI" "$1" +} + +ansi::bgCyan() { + printf '%s46m' "$ANSI_CSI" +} + +ansi::bgCyanIntense() { + printf '%s106m' "$ANSI_CSI" +} + +ansi::bgGreen() { + printf '%s42m' "$ANSI_CSI" +} + +ansi::bgGreenIntense() { + printf '%s102m' "$ANSI_CSI" +} + +ansi::bgMagenta() { + printf '%s45m' "$ANSI_CSI" +} + +ansi::bgMagentaIntense() { + printf '%s105m' "$ANSI_CSI" +} + +ansi::bgRed() { + printf '%s41m' "$ANSI_CSI" +} + +ansi::bgRgb() { + printf '%s48;2;%s;%s;%sm' "$ANSI_CSI" "$1" "$2" "$3" +} + +ansi::bgRedIntense() { + printf '%s101m' "$ANSI_CSI" +} + +ansi::bgWhite() { + printf '%s47m' "$ANSI_CSI" +} + +ansi::bgWhiteIntense() { + printf '%s107m' "$ANSI_CSI" +} + +ansi::bgYellow() { + printf '%s43m' "$ANSI_CSI" +} + +ansi::bgYellowIntense() { + printf '%s103m' "$ANSI_CSI" +} + +ansi::bold() { + printf '%s1m' "$ANSI_CSI" +} + +ansi::color() { + printf '%s38;5;%sm' "$ANSI_CSI" "$1" +} + +ansi::colorCodes() { + local code i j + + printf 'Standard: ' + ansi::bold + ansi::white + + for code in 0 1 2 3 4 5 6 7; do + if [[ "$code" == 7 ]]; then + ansi::black + fi + ansi::colorCodePatch "$code" + done + + ansi::resetForeground + ansi::normal + printf '\nIntense: ' + ansi::white + + for code in 8 9 10 11 12 13 14 15; do + if [[ "$code" == 9 ]]; then + ansi::black + fi + ansi::colorCodePatch "$code" + done + + ansi::resetForeground + printf '\n\n' + + # for i in 16 22 28 34 40 46; do + for i in 16 22 28; do + for j in $i $((i+36)) $((i+72)) $((i+108)) $((i+144)) $((i+180)); do + ansi::white + ansi::bold + + for code in $j $((j+1)) $((j+2)) $((j+3)) $((j+4)) $((j+5)); do + ansi::colorCodePatch "$code" + done + + ansi::normal + ansi::resetForeground + printf ' ' + ansi::black + + for code in $((j+18)) $((j+19)) $((j+20)) $((j+21)) $((j+22)) $((j+23)); do + ansi::colorCodePatch "$code" + done + + ansi::resetForeground + printf '\n' + done + + printf '\n' + done + + printf 'Grays: ' + ansi::bold + ansi::white + + for code in 232 233 234 235 236 237 238 239 240 241 242 243; do + ansi::colorCodePatch "$code" + done + + ansi::resetForeground + ansi::normal + printf '\n ' + ansi::black + + for code in 244 245 246 247 248 249 250 251 252 253 254 255; do + ansi::colorCodePatch "$code" + done + + ansi::resetForeground + printf '\n' +} + +ansi::colorCodePatch() { + ansi::bgColor "$1" + printf ' %3s ' "$1" + ansi::resetBackground } ansi::colorTable() { - local FNB_LOWER FNB_UPPER PADDED + local colorLabel counter fnbLower fnbUpper functionName IFS resetFunction - FNB_LOWER="$(ansi::colorize 2 22 f)n$(ansi::colorize 1 22 b)" - FNB_UPPER="$(ansi::colorize 2 22 F)N$(ansi::colorize 1 22 B)" - printf 'bold %s ' "$(ansi::colorize 1 22 Sample)" - printf 'faint %s ' "$(ansi::colorize 2 22 Sample)" - printf 'italic %s\n' "$(ansi::colorize 3 23 Sample)" - printf 'underline %s ' "$(ansi::colorize 4 24 Sample)" - printf 'blink %s ' "$(ansi::colorize 5 25 Sample)" - printf 'inverse %s\n' "$(ansi::colorize 7 27 Sample)" - printf 'invisible %s\n' "$(ansi::colorize 8 28 Sample)" - printf 'strike %s ' "$(ansi::colorize 9 29 Sample)" - printf 'fraktur %s ' "$(ansi::colorize 20 23 Sample)" - printf 'double-underline%s\n' "$(ansi::colorize 21 24 Sample)" - printf 'frame %s ' "$(ansi::colorize 51 54 Sample)" - printf 'encircle %s ' "$(ansi::colorize 52 54 Sample)" - printf 'overline%s\n' "$(ansi::colorize 53 55 Sample)" + fnbLower="$( + ansi::faint + printf f + ansi::normal + printf n + ansi::bold + printf b + ansi::normal + )" + fnbUpper="$( + ansi::faint + printf F + ansi::normal + printf N + ansi::bold + printf B + ansi::normal + )" + IFS=$' \n' + counter= + + while read -r colorLabel functionName resetFunction; do + printf -- '--%s ' "$colorLabel" + $functionName + printf 'Sample' + $resetFunction + + if [[ "$counter" == "x" ]]; then + counter= + printf '\n' + else + counter=x + ansi::column 40 + fi + done < /dev/null; then + if [[ "$(tput colors)" -lt 8 ]]; then + return 1 + fi + + return 0 + fi + + # Query the console and see if we get ANSI codes back. + # CSI 0 c == CSI c == Primary Device Attributes. # Idea: CSI c # Response = CSI ? 6 [234] ; 2 2 c - # The "22" means ANSI color - printf "can't tell yet\n" + # The "22" means ANSI color, but terminals don't need to send that back. + # If we get anything back, let's assume it works. + ansi::report c "$ANSI_CSI?" c || return 1 + [[ -n "$ANSI_REPORT" ]] +} + +ansi::italic() { + printf '%s3m' "$ANSI_CSI" +} + +ansi::line() { + printf '%s%sd' "$ANSI_CSI" "${1-}" +} + +ansi::lineRelative() { + printf '%s%se' "$ANSI_CSI" "${1-}" +} + +ansi::magenta() { + printf '%s35m' "$ANSI_CSI" +} + +ansi::magentaIntense() { + printf '%s95m' "$ANSI_CSI" +} + +ansi::nextLine() { + printf '%s%sE' "$ANSI_CSI" "${1-}" +} + +ansi::noBlink() { + printf '%s25m' "$ANSI_CSI" +} + +ansi::noBorder() { + printf '%s54m' "$ANSI_CSI" +} + +ansi::noInverse() { + printf '%s27m' "$ANSI_CSI" +} + +ansi::normal() { + printf '%s22m' "$ANSI_CSI" +} + +ansi::noOverline() { + printf '%s55m' "$ANSI_CSI" +} + +ansi::noStrike() { + printf '%s29m' "$ANSI_CSI" +} + +ansi::noUnderline() { + printf '%s24m' "$ANSI_CSI" +} + +ansi::overline() { + printf '%s53m' "$ANSI_CSI" +} + +ansi::plain() { + printf '%s23m' "$ANSI_CSI" +} + +ansi::position() { + local position="${1-}" + printf '%s%sH' "$ANSI_CSI" "${position/,/;}" +} + +ansi::previousLine() { + printf '%s%sF' "$ANSI_CSI" "${1-}" +} + +ansi::rapidBlink() { + printf '%s6m' "$ANSI_CSI" +} + +ansi::red() { + printf '%s31m' "$ANSI_CSI" +} + +ansi::redIntense() { + printf '%s91m' "$ANSI_CSI" +} + +ansi::repeat() { + printf '%s%sb' "$ANSI_CSI" "${1-}" } ansi::report() { - local BUFF C + local buff c report - REPORT="" - printf "%s%s" "$CSI" "$1" - read -r -N ${#2} -s -t 1 BUFF + # Write to stderr to bypass piping, which lets this work: + # ansi --report-window-chars | cut -d , -f 1 + printf "%s%s" "$ANSI_CSI" "$1" >&2 + report="" + read -r -N "${#2}" -s -t 1 buff - if [ "$BUFF" != "$2" ]; then + if [ "$buff" != "$2" ]; then return 1 fi - read -r -N ${#3} -s -t 1 BUFF + read -r -N "${#3}" -s -t 1 buff - while [ "$BUFF" != "$3" ]; do - REPORT="$REPORT${BUFF:0:1}" - read -r -N 1 -s -t 1 C || exit 1 - BUFF="${BUFF:1}$C" + while [[ "$buff" != "$3" ]]; do + report="$report${buff:0:1}" + read -r -N 1 -s -t 1 c || exit 1 + buff="${buff:1}$c" done + + ANSI_REPORT=$report +} + +ansi::reportPosition() { + ansi::report 6n "$ANSI_CSI" R || return 1 + printf '%s\n' "${ANSI_REPORT//;/,}" +} + +ansi::reportIcon() { + ansi::report 20t "${ANSI_OSC}L" "$ANSI_ST" || return 1 + printf '%s\n' "${ANSI_REPORT//;/,}" +} + +ansi::reportScreenChars() { + ansi::report 19t "${ANSI_CSI}9;" t || return 1 + printf '%s\n' "${ANSI_REPORT//;/,}" +} + +ansi::reportTitle() { + ansi::report 21t "${ANSI_OSC}l" "$ANSI_ST" || return 1 + printf '%s\n' "${ANSI_REPORT//;/,}" +} + +ansi::reportWindowChars() { + ansi::report 18t "${ANSI_CSI}8;" t || return 1 + printf '%s\n' "${ANSI_REPORT//;/,}" +} + +ansi::reportWindowPixels() { + ansi::report 14t "${ANSI_CSI}4;" t || return 1 + printf '%s\n' "${ANSI_REPORT//;/,}" +} + +ansi::reportWindowPosition() { + ansi::report 13t "${ANSI_CSI}3;" t || return 1 + printf '%s\n' "${ANSI_REPORT//;/,}" +} + +ansi::reportWindowState() { + ansi::report 11t "$ANSI_CSI" t || return 1 + case "$ANSI_REPORT" in + 1) + printf 'open\n' + ;; + + 2) + printf 'iconified\n' + ;; + + *) + printf 'unknown (%s)\n' "$ANSI_REPORT" + ;; + esac +} + +ansi::reset() { + ansi::resetColor + ansi::resetFont + ansi::eraseDisplay 2 + ansi::position "1;1" + ansi::showCursor +} + +ansi::resetAttributes() { + printf '%s22;23;24;25;27;28;29;54;55m' "$ANSI_CSI" +} + +ansi::resetBackground() { + printf '%s49m' "$ANSI_CSI" +} + +ansi::resetColor() { + printf '%s0m' "$ANSI_CSI" +} + +ansi::resetFont() { + printf '%s10m' "$ANSI_CSI" +} + +ansi::resetForeground() { + printf '%s39m' "$ANSI_CSI" +} + +ansi::resetIdeogram() { + printf '%s65m' "$ANSI_CSI" +} + +ansi::restoreCursor() { + printf '%su' "$ANSI_CSI" +} + +ansi::rgb() { + printf '%s38;2;%s;%s;%sm' "$ANSI_CSI" "$1" "$2" "$3" +} + +ansi::saveCursor() { + printf '%ss' "$ANSI_CSI" +} + +ansi::scrollDown() { + printf '%s%sT' "$ANSI_CSI" "${1-}" +} + +ansi::scrollUp() { + printf '%s%sS' "$ANSI_CSI" "${1-}" +} + +ansi::setIcon() { + printf '%s1;%s%s' "$ANSI_OSC" "${1-}" "$ANSI_ST" +} + +ansi::setTitle() { + printf '%s2;%s%s' "$ANSI_OSC" "${1-}" "$ANSI_ST" +} + +ansi::showCursor() { + printf '%s?25h' "$ANSI_CSI" } ansi::showHelp() { @@ -126,19 +690,19 @@ For instance, using --down will move the cursor down one line and --down=10 moves the cursor down 10 lines. Display Manipulation - --insert-chars[=N], --ich[=N] + --insert-chars[=N], --insert-char[=N], --ich[=N] Insert blanks at cursor, shifting the line right. --erase-display[=N], --ed[=N] Erase in display. 0=below, 1=above, 2=all, 3=saved. - --erase-line[=N], --el[=N] + --erase-line=[N], --el[=N] Erase in line. 0=right, 1=left, 2=all. - --insert-lines[=N], --il[=N] - --delete-lines[=N], --dl[=N] - --delete-chars[=N], --dch[=N] + --insert-lines[=N], --insert-line[=N], --il[=N] + --delete-lines[=N], --delete-line[=N], --dl[=N] + --delete-chars[=N], --delete-char[=N], --dch[=N] --scroll-up[=N], --su[=N] --scroll-down[=N], --sd[=N] - --erase-chars[=N], --ech[=N] + --erase-chars[=N], --erase-char[=N], --ech[=N] --repeat[=N], --rep[=N] Repeat preceding character N times. Cursor: @@ -147,7 +711,7 @@ Cursor: --forward[=N], --cuf[=N] --backward[=N], --cub[=N] --next-line[=N], --cnl[=N] - --prev-line[=N], --cpl[=N] + --previous-line[=N], --prev-line[=N], --cpl[=N] --column[=N], --cha[=N] --position[=[ROW],[COL]], --cup[=[ROW],[=COL]] --tab-forward[=N] Move forward N tab stops. @@ -163,26 +727,37 @@ Cursor: is also used. --show-cursor -Colors: +Text: Attributes: - --bold, --faint, --italic, --underline, --blink, --inverse, - --invisible, --strike, --fraktur, --double-underline, --frame, - --encircle, --overline + --bold, --faint, --normal + --italic, --fraktur, --plain + --underline, --double-underline, --no-underline + --blink, --rapid-blink, --no-blink + --inverse, --no-inverse + --invisible, --visible + --strike, --no-strike + --frame, --encircle, --no-border + --overline, --no-overline + --ideogram-right, --ideogram-right-double, --ideogram-left, + --ideogram-left-double, --ideogram-stress, --reset-ideogram + --font=NUM (NUM must be from 0 through 9 and 0 is the primary font) Foreground: --black, --red, --green, --yellow, --blue, --magenta, --cyan, --white, --black-intense, --red-intense, --green-intense, --yellow-intense, - --blue-intense, --magenta-intense, --cyan-intense, --white-intense + --blue-intense, --magenta-intense, --cyan-intense, --white-intense, + --color=CODE, --rgb=R,G,B Background: --bg-black, --bg-red, --bg-green, --bg-yellow, --bg-blue, --bg-magenta, --bg-cyan, --bg-white, --bg-black-intense, --bg-red-intense, --bg-green-intense, --bg-yellow-intense, --bg-blue-intense, --bg-magenta-intense, --bg-cyan-intense, - --bg-white-intense + --bg-white-intense, --bg-color=CODE, --bg-rgb=R,G,B Reset: --reset-attrib Removes bold, italics, etc. --reset-foreground Sets foreground to default color. --reset-background Sets background to default color. --reset-color Resets attributes, foreground, background. + --reset-font Switches back to the primary font. Report: ** NOTE: These require reading from stdin. Results are sent to stdout. @@ -198,6 +773,7 @@ Report: Miscellaneous: --color-table Display a color table. + --color-codes Show the different color codes. --icon=NAME Set the terminal's icon name. --title=TITLE Set the terminal's window title. --no-restore Do not issue reset codes when changing colors. @@ -205,464 +781,834 @@ Miscellaneous: normally the color is restored to default afterwards. With this flag, the color will stay green even when the command finishes. - -n, --newline Add a newline at the end. - --escape Allow text passed in to contain escape sequences. + -n, --no-newline Suppress newline at the end of the line. --bell Add the terminal's bell sequence to the output. --reset Reset colors, clear screen, show cursor, move - cursor to 1,1. + cursor to (1,1), and reset the font. EOF } -ansi() { - # Handle long options until we hit an unrecognized thing - local CONTINUE=true - local RESTORE=true - local NEWLINE=false - local ESCAPE=false - local ESC=$'\033' - local CSI="${ESC}[" - local OSC="${ESC}]" - local ST="${ESC}\\" - local OUTPUT="" - local SUFFIX="" - local BELL=$'\007' +ansi::strike() { + printf '%s9m' "$ANSI_CSI" +} - while $CONTINUE; do +ansi::tabBackward() { + printf '%s%sZ' "$ANSI_CSI" "${1-}" +} + +ansi::tabForward() { + printf '%s%sI' "$ANSI_CSI" "${1-}" +} + +ansi::underline() { + printf '%s4m' "$ANSI_CSI" +} + +ansi::up() { + printf '%s%sA' "$ANSI_CSI" "${1-}" +} + +ansi::visible() { + printf '%s28m' "$ANSI_CSI" +} + +ansi::white() { + printf '%s37m' "$ANSI_CSI" +} + +ansi::whiteIntense() { + printf '%s97m' "$ANSI_CSI" +} + +ansi::yellow() { + printf '%s33m' "$ANSI_CSI" +} + +ansi::yellowIntense() { + printf '%s93m' "$ANSI_CSI" +} + +ansi() { + local addNewline b g m r readOptions restoreText restoreCursorPosition restoreCursorVisibility supported triggerRestore + local m10 m22 m23 m24 m25 m27 m28 m29 m39 m49 m54 m55 m65 + + addNewline=true + m10= + m22= + m23= + m24= + m25= + m27= + m28= + m29= + m39= + m49= + m54= + m55= + m65= + readOptions=true + restoreCursorPosition=false + restoreCursorVisibility=false + restoreText=false + supported=true + triggerRestore=true + + if ! ansi::isAnsiSupported; then + supported=false + fi + + while $readOptions; do case "$1" in --help | -h | -\?) ansi::showHelp + return 0 ;; # Display Manipulation - --insert-chars | --insert-chars=* | --ich | --ich=*) - ansi::addCode "$1" @ + --insert-chars | --insert-char | --ich) + $supported && ansi::insertChars ;; - --erase-display | --erase-display=* | --ed | --ed=*) - ansi::addCode "$1" J + --insert-chars=* | insert-char=* | --ich=*) + $supported && ansi::insertChars "${1#*=}" ;; - --erase-line | --erase-line=* | --el | --el=*) - ansi::addCode "$1" K + --erase-display | --ed) + $supported && ansi::eraseDisplay ;; - --insert-lines | --insert-lines=* | --il | --il=*) - ansi::addCode "$1" L + --erase-display=* | --ed=*) + $supported && ansi::eraseDisplay "${1#*=}" ;; - --delete-lines | --delete-lines=* | --dl | --dl=*) - ansi::addCode "$1" M + --erase-line | --el) + $supported && ansi::eraseLine ;; - --delete-chars | --delete-chars=* | --dch | --dch=*) - ansi::addCode "$1" P + --erase-line=* | --el=*) + $supported && ansi::eraseLine "${1#*=}" ;; - --scroll-up | --scroll-up=* | --su | --su=*) - ansi::addCode "$1" S + --insert-lines | --insert-line | --il) + $supported && ansi::insertLines ;; - --scroll-down | --scroll-down=* | --sd | --sd=*) - ansi::addCode "$1" T + --insert-lines=* | --insert-line=* | --il=*) + $supported && ansi::insertLines "${1#*=}" ;; - --erase-chars | --erase-chars=* | --ech | --ech=*) - ansi::addCode "$1" X + --delete-lines | --delete-line | --dl) + $supported && ansi::deleteLines ;; - --repeat | --repeat=* | --rep | --rep=N) - ansi::addCode "$1" b + --delete-lines=* | --delete-line=* | --dl=*) + $supported && ansi::deleteLines "${1#*=}" + ;; + + --delete-chars | --delete-char | --dch) + $supported && ansi::deleteChars + ;; + + --delete-chars=* | --delete-char=* | --dch=*) + $supported && ansi::deleteChars "${1#*=}" + ;; + + --scroll-up | --su) + $supported && ansi::scrollUp + ;; + + --scroll-up=* | --su=*) + $supported && ansi::scrollUp "${1#*=}" + ;; + + --scroll-down | --sd) + $supported && ansi::scrollDown + ;; + + --scroll-down=* | --sd=*) + $supported && ansi::scrollDown "${1#*=}" + ;; + + --erase-chars | --erase-char | --ech) + $supported && ansi::eraseChars + ;; + + --erase-chars=* | --erase-char=* | --ech=*) + $supported && ansi::eraseChars "${1#*=}" + ;; + + --repeat | --rep) + $supported && ansi::repeat + ;; + + --repeat=* | --rep=N) + $supported && ansi::repeat "${1#*=}" ;; # Cursor Positioning - --up | --up=* | --cuu | --cuu=*) - ansi::addCode "$1" A + --up | --cuu) + $supported && ansi::up ;; - --down | --down=* | --cud | --cud=*) - ansi::addCode "$1" B + --up=* | --cuu=*) + $supported && ansi::up "${1#*=}" ;; - --forward | --forward=* | --cuf | --cuf=*) - ansi::addCode "$1" C + --down | --cud) + $supported && ansi::down ;; - --backward | --backward=*| --cub | --cub=*) - ansi::addCode "$1" D + --down=* | --cud=*) + $supported && ansi::down "${1#*=}" ;; - --next-line | --next-line=* | --cnl | --cnl=*) - ansi::addCode "$1" E + --forward | --cuf) + $supported && ansi::forward ;; - --prev-line | --prev-line=* | --cpl | --cpl=*) - ansi::addCode "$1" F + --forward=* | --cuf=*) + $supported && ansi::forward "${1#*=}" ;; - --column | --column=* | --cha | --cha=*) - ansi::addCode "$1" G + --backward | --cub) + $supported && ansi::backward ;; - --position | --position=* | --cup | --cup=*) - ansi::addCode "$1" H + --backward=* | --cub=*) + $supported && ansi::backward "${1#*=}" ;; - --tab-forward | --tab-forward=* | --cht | --cht=*) - ansi::addCode "$1" I + --next-line | --cnl) + $supported && ansi::nextLine ;; - --tab-backward | --tab-backward=* | --cbt | --cbt=*) - ansi::addCode "$1" Z + --next-line=* | --cnl=*) + $supported && ansi::nextLine "${1#*=}" ;; - --column-relative | --column-relative=* | --hpr | --hpr=*) - ansi::addCode "$1" 'a' + --previous-line | --prev-line | --cpl) + $supported && ansi::previousLine ;; - --line | --line=* | --vpa | --vpa=*) - ansi::addCode "$1" 'd' + --previous-line=* | --prev-line=* | --cpl=*) + $supported && ansi::previousLine "${1#*=}" ;; - --line-relative | --line-relative=* | --vpr | --vpr=*) - ansi::addCode "$1" 'e' + --column | --cha) + $supported && ansi::column + ;; + + --column=* | --cha=*) + $supported && ansi::column "${1#*=}" + ;; + + --position | --cup) + $supported && ansi::position + ;; + + --position=* | --cup=*) + $supported && ansi::position "${1#*=}" + ;; + + --tab-forward | --cht) + $supported && ansi::tabForward + ;; + + --tab-forward=* | --cht=*) + $supported && ansi::tabForward "${1#*=}" + ;; + + --tab-backward | --cbt) + $supported && ansi::tabBackward + ;; + + --tab-backward=* | --cbt=*) + $supported && ansi::tabBackward "${1#*=}" + ;; + + --column-relative | --hpr) + $supported && ansi::columnRelative + ;; + + --column-relative=* | --hpr=*) + $supported && ansi::columnRelative "${1#*=}" + ;; + + --line | --vpa) + $supported && ansi::line + ;; + + --line=* | --vpa=*) + $supported && ansi::line "${1#*=}" + ;; + + --line-relative | --vpr) + $supported && ansi::lineRelative + ;; + + --line-relative=* | --vpr=*) + $supported && ansi::lineRelative "${1#*=}" ;; --save-cursor) - OUTPUT="$OUTPUT${CSI}s" - SUFFIX="${CSI}u$SUFFIX" + $supported && ansi::saveCursor + restoreCursorPosition=true ;; --restore-cursor) - OUTPUT="$OUTPUT${CSI}u" + $supported && ansi::restoreCursor ;; --hide-cursor) - OUTPUT="$OUTPUT${CSI}?25l" - SUFFIX="${CSI}?25h" + $supported && ansi::hideCursor + restoreCursorVisibility=true ;; --show-cursor) - OUTPUT="$OUTPUT${CSI}?25h" + $supported && ansi::showCursor ;; # Colors - Attributes --bold) - ansi::addColor 1 22 + $supported && ansi::bold + restoreText=true + m22="22;" ;; --faint) - ansi::addColor 2 22 + $supported && ansi::faint + restoreText=true + m22="22;" ;; --italic) - ansi::addColor 3 23 + $supported && ansi::italic + restoreText=true + m23="23;" ;; --underline) - ansi::addColor 4 24 + $supported && ansi::underline + restoreText=true + m24="24;" ;; --blink) - ansi::addColor 5 25 + $supported && ansi::blink + restoreText=true + m25="25;" + ;; + + --rapid-blink) + $supported && ansi::rapidBlink + restoreText=true + m25="25;" ;; --inverse) - ansi::addColor 7 27 + $supported && ansi::inverse + restoreText=true + m27="27;" ;; --invisible) - ansi::addColor 8 28 + $supported && ansi::invisible + restoreText=true + m28="28;" ;; --strike) - ansi::addColor 9 20 + $supported && ansi::strike + restoreText=true + m29="29;" + ;; + + --font|--font=0) + $supported && ansi::resetFont + ;; + + --font=[123456789]) + $supported && ansi::font "${1#*=}" + restoreText=true + m10="10;" ;; --fraktur) - ansi::addColor 20 23 + $supported && ansi::fraktur + restoreText=true + m23="23;" ;; --double-underline) - ansi::addColor 21 24 + $supported && ansi::doubleUnderline + restoreText=true + m24="24;" + ;; + + --normal) + $supported && ansi::normal + ;; + + --plain) + $supported && ansi::plain + ;; + + --no-underline) + $supported && ansi::noUnderline + ;; + + --no-blink) + $supported && ansi::noBlink + ;; + + --no-inverse) + $supported && ansi::noInverse + ;; + + --visible) + $supported && ansi::visible + ;; + + --no-strike) + $supported && ansi::noStrike ;; --frame) - ansi::addColor 51 54 + $supported && ansi::frame + restoreText=true + m54="54;" ;; --encircle) - ansi::addColor 52 54 + $supported && ansi::encircle + restoreText=true + m54="54;" ;; --overline) - ansi::addColor 53 55 + $supported && ansi::overline + restoreText=true + m55="55;" + ;; + + --no-border) + $supported && ansi::noBorder + ;; + + --no-overline) + $supported && ansi::noOverline ;; # Colors - Foreground --black) - ansi::addColor 30 39 + $supported && ansi::black + restoreText=true + m39="39;" ;; --red) - ansi::addColor 31 39 + $supported && ansi::red + restoreText=true + m39="39;" ;; --green) - ansi::addColor 32 39 + $supported && ansi::green + restoreText=true + m39="39;" ;; --yellow) - ansi::addColor 33 39 + $supported && ansi::yellow + restoreText=true + m39="39;" ;; --blue) - ansi::addColor 34 39 + $supported && ansi::blue + restoreText=true + m39="39;" ;; --magenta) - ansi::addColor 35 39 + $supported && ansi::magenta + restoreText=true + m39="39;" ;; --cyan) - ansi::addColor 36 39 + $supported && ansi::cyan + restoreText=true + m39="39;" ;; --white) - ansi::addColor 37 39 + $supported && ansi::white + restoreText=true + m39="39;" ;; --black-intense) - ansi::addColor 90 39 + $supported && ansi::blackIntense + restoreText=true + m39="39;" ;; --red-intense) - ansi::addColor 91 39 + $supported && ansi::redIntense + restoreText=true + m39="39;" ;; --green-intense) - ansi::addColor 92 39 + $supported && ansi::greenIntense + restoreText=true + m39="39;" ;; --yellow-intense) - ansi::addColor 93 39 + $supported && ansi::yellowIntense + restoreText=true + m39="39;" ;; --blue-intense) - ansi::addColor 94 39 + $supported && ansi::blueIntense + restoreText=true + m39="39;" ;; --magenta-intense) - ansi::addColor 95 39 + $supported && ansi::magentaIntense + restoreText=true + m39="39;" ;; --cyan-intense) - ansi::addColor 96 39 + $supported && ansi::cyanIntense + restoreText=true + m39="39;" ;; --white-intense) - ansi::addColor 97 39 + $supported && ansi::whiteIntense + restoreText=true + m39="39;" + ;; + + --rgb=*,*,*) + r=${1#*=} + b=${r##*,} + g=${r#*,} + g=${g%,*} + r=${r%%,*} + $supported && ansi::rgb "$r" "$g" "$b" + restoreText=true + m39="39;" + ;; + + --color=*) + $supported && ansi::color "${1#*=}" + restoreText=true + m39="39;" ;; # Colors - Background --bg-black) - ansi::addColor 40 49 + $supported && ansi::bgBlack + restoreText=true + m49="49;" ;; --bg-red) - ansi::addColor 41 49 + $supported && ansi::bgRed + restoreText=true + m49="49;" ;; --bg-green) - ansi::addColor 42 49 + $supported && ansi::bgGreen + restoreText=true + m49="49;" ;; --bg-yellow) - ansi::addColor 43 49 + $supported && ansi::bgYellow + restoreText=true + m49="49;" ;; --bg-blue) - ansi::addColor 44 49 + $supported && ansi::bgBlue + restoreText=true + m49="49;" ;; --bg-magenta) - ansi::addColor 45 49 + $supported && ansi::bgMagenta + restoreText=true + m49="49;" ;; --bg-cyan) - ansi::addColor 46 49 + $supported && ansi::bgCyan + restoreText=true + m49="49;" ;; --bg-white) - ansi::addColor 47 49 + $supported && ansi::bgWhite + restoreText=true + m49="49;" ;; --bg-black-intense) - ansi::addColor 100 49 + $supported && ansi::bgBlackIntense + restoreText=true + m49="49;" ;; --bg-red-intense) - ansi::addColor 101 49 + $supported && ansi::bgRedIntense + restoreText=true + m49="49;" ;; --bg-green-intense) - ansi::addColor 102 49 + $supported && ansi::bgGreenIntense + restoreText=true + m49="49;" ;; --bg-yellow-intense) - ansi::addColor 103 49 + $supported && ansi::bgYellowIntense + restoreText=true + m49="49;" ;; --bg-blue-intense) - ansi::addColor 104 49 + $supported && ansi::bgBlueIntense + restoreText=true + m49="49;" ;; --bg-magenta-intense) - ansi::addColor 105 49 + $supported && ansi::bgMagentaIntense + restoreText=true + m49="49;" ;; --bg-cyan-intense) - ansi::addColor 106 49 + $supported && ansi::bgCyanIntense + restoreText=true + m49="49;" ;; --bg-white-intense) - ansi::addColor 107 49 + $supported && ansi::bgWhiteIntense + restoreText=true + m49="49;" + ;; + + --bg-rgb=*,*,*) + r=${1#*=} + b=${r##*,} + g=${r#*,} + g=${g%,*} + r=${r%%,*} + $supported && ansi::bgRgb "$r" "$g" "$b" + restoreText=true + m49="49;" + ;; + + --bg-color=*) + $supported && ansi::bgColor "${1#*=}" + restoreText=true + m49="49;" ;; # Colors - Reset --reset-attrib) - OUTPUT="$OUTPUT${CSI}22;23;24;25;27;28;29;54;55m" + $supported && ansi::resetAttributes ;; --reset-foreground) - OUTPUT="$OUTPUT${CSI}39m" + $supported && ansi::resetForeground ;; --reset-background) - OUTPUT="$OUTPUT${CSI}39m" + $supported && ansi::resetBackground ;; --reset-color) - OUTPUT="$OUTPUT${CSI}0m" + $supported && ansi::resetColor + ;; + + --reset-font) + $supported && ansi::resetFont ;; # Reporting --report-position) - ansi::report 6n "$CSI" R || exit 1 - printf '%s\n' "${REPORT//;/,}" + $supported || return 1 + ansi::reportPosition || return $? ;; --report-window-state) - ansi::report 11t "$CSI" t || exit 1 - case "$REPORT" in - 1) - printf 'open\n' - ;; - - 2) - printf 'iconified\n' - ;; - - *) - printf 'unknown (%s)\n' "$REPORT" - ;; - esac + $supported || return 1 + ansi::reportWindowState || return $? ;; --report-window-position) - ansi::report 13t "${CSI}3;" t || exit 1 - printf '%s\n' "${REPORT//;/,}" + $supported || return 1 + ansi::reportWindowPosition || return $? ;; --report-window-pixels) - ansi::report 14t "${CSI}4;" t || exit 1 - printf '%s\n' "${REPORT//;/,}" + $supported || return 1 + ansi::reportWindowPixels || return $? ;; --report-window-chars) - ansi::report 18t "${CSI}8;" t || exit 1 - printf '%s\n' "${REPORT//;/,}" + $supported || return 1 + ansi::reportWindowChars || return $? ;; --report-screen-chars) - ansi::report 19t "${CSI}9;" t || exit 1 - printf '%s\n' "${REPORT//;/,}" + $supported || return 1 + ansi::reportScreenChars || return $? ;; --report-icon) - ansi::report 20t "${OSC}L" "$ST" || exit 1 - printf '%s\n' "$REPORT" + $supported || return 1 + ansi::reportIcon || return $? ;; --report-title) - ansi::report 21t "${OSC}l" "$ST" || exit 1 - printf '%s\n' "$REPORT" + $supported || return 1 + ansi::reportTitle || return $? + ;; + + --ideogram-right) + $supported && ansi::ideogramRight + restoreText=true + m65="65;" + ;; + + --ideogram-right-double) + $supported && ansi::ideogramRightDouble + restoreText=true + m65="65;" + ;; + + --ideogram-left) + $supported && ansi::ideogramLeft + restoreText=true + m65="65;" + ;; + + --ideogram-left-double) + $supported && ansi::ideogramLeftDouble + restoreText=true + m65="65;" + ;; + + --reset-ideogram) + $supported && ansi::noIdeogram ;; # Miscellaneous + --color-codes) + if ! $supported; then + echo "ANSI is not supported in this terminal." + else + ansi::colorCodes + fi + + return 0 + ;; + --color-table) - ansi::colorTable + if ! $supported; then + echo "ANSI is not supported in this terminal." + else + ansi::colorTable + fi + + return 0 + ;; + + --icon) + $supported && ansi::setIcon "" ;; --icon=*) - OUTPUT="$OUTPUT${OSC}1;${1#*=}$ST" + $supported && ansi::setIcon "${1#*=}" + ;; + + --title) + $supported && ansi::setTitle "" ;; --title=*) - OUTPUT="$OUTPUT${OSC}2;${1#*=}$ST" + $supported && ansi::setTitle "${1#*=}" ;; --no-restore) - RESTORE=false + triggerRestore=false ;; - -n | --newline) - NEWLINE=true - ;; - - --escape) - ESCAPE=true + -n | --no-newline) + addNewline=false ;; --bell) - OUTPUT="$OUTPUT$BELL" + ansi::bell ;; --reset) - # 0m - reset all colors and attributes - # 2J - clear terminal - # 1;1H - move to 1,1 - # ?25h - show cursor - OUTPUT="$OUTPUT${CSI}0m${CSI}2J${CSI}1;1H${CSI}?25h" + $supported || return 0 + ansi::reset ;; --) - CONTINUE=false + readOptions=false shift ;; *) - CONTINUE=false + readOptions=false ;; esac - if $CONTINUE; then + if $readOptions; then shift fi done - printf '%s' "$OUTPUT" + printf '%s' "${1-}" + shift || : - if $ESCAPE; then - printf '%s' "${1+"$@"}" - else - printf '%s' "${1+"$@"}" + if [[ "$#" -gt 0 ]]; then + printf "${IFS:0:1}%s" "${@}" fi - if $RESTORE; then - printf '%s' "$SUFFIX" + if $supported && $triggerRestore; then + if $restoreCursorPosition; then + ansi::restoreCursor + fi + + if $restoreCursorVisibility; then + ansi::showCursor + fi + + if $restoreText; then + m="$m10$m22$m23$m24$m25$m27$m28$m29$m$m39$m49$m54$m55$m65" + printf '%s%sm' "$ANSI_CSI" "${m%;}" + fi fi - if $NEWLINE; then + if $addNewline; then printf '\n' fi } @@ -670,6 +1616,5 @@ ansi() { # Run if not sourced if [[ "$0" == "${BASH_SOURCE[0]}" ]]; then - ansi "$@" + ansi "$@" || exit $? fi - diff --git a/bin/desk b/bin/desk index ec105a5..7b786f4 100755 --- a/bin/desk +++ b/bin/desk @@ -287,7 +287,7 @@ get_running_shell() { else # Strip leading dash for login shells. # If the parent process is a login shell, guess bash. - local CMDLINE_SHELL=$(ps -o args -p $PPID | tail -1 | sed -e 's/login/bash/' -e 's/^-//') + local CMDLINE_SHELL=$(ps -o comm= -p $PPID | tail -1 | sed -e 's/login/bash/' -e 's/^-//') fi if [ ! -z "$CMDLINE_SHELL" ]; then @@ -331,4 +331,3 @@ case "$1" in *) cmd_current "$@" ;; esac exit 0 - diff --git a/bin/mo b/bin/mo index 458472e..55496ed 100755 --- a/bin/mo +++ b/bin/mo @@ -141,15 +141,16 @@ mo() ( # # Returns nothing. moCallFunction() { - local moCommand + local moArgs + + moArgs=() # shellcheck disable=SC2031 - if [[ -n "$MO_ALLOW_FUNCTION_ARGUMENTS" ]]; then - printf -v moCommand "%q %q %s" "$1" "$2" "$3" - eval "$moCommand" - else - "$1" "$2" + if [[ -n "${MO_ALLOW_FUNCTION_ARGUMENTS-}" ]]; then + moArgs=$3 fi + + echo -n "$2" | eval "$1" "$moArgs" } @@ -834,15 +835,15 @@ moShow() { moSplit moNameParts "$1" "." - if [[ -z "${moNameParts[1]}" ]]; then + if [[ -z "${moNameParts[1]-}" ]]; then if moIsArray "$1"; then eval moJoin moJoined "," "\${$1[@]}" echo -n "$moJoined" else # shellcheck disable=SC2031 - if [[ -z "$MO_FAIL_ON_UNSET" ]] || moTestVarSet "$1"; then + if moTestVarSet "$1"; then echo -n "${!1}" - else + elif [[ -n "${MO_FAIL_ON_UNSET-}" ]]; then echo "Env variable not set: $1" >&2 exit 1 fi @@ -1029,15 +1030,17 @@ moTrimWhitespace() { # Returns nothing. moUsage() { grep '^#/' "${MO_ORIGINAL_COMMAND}" | cut -c 4- + echo "" + set | grep ^MO_VERSION= } # Save the original command's path for usage later MO_ORIGINAL_COMMAND="$(cd "${BASH_SOURCE[0]%/*}" || exit 1; pwd)/${BASH_SOURCE[0]##*/}" +MO_VERSION="2.0.4" # If sourced, load all functions. # If executed, perform the actions as expected. if [[ "$0" == "${BASH_SOURCE[0]}" ]] || [[ -z "${BASH_SOURCE[0]}" ]]; then mo "$@" fi - diff --git a/bin/nma b/bin/nma deleted file mode 100755 index b789df6..0000000 --- a/bin/nma +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -out=$(mktemp /tmp/nma.XXXXXXXX) -curl -s -d "apikey=1e9cfe3bddab21f271b742eb04f9918a76ad0ef0333be7d3" -d "application=Server" -d "event=megumi.eeleater.org" --data-urlencode "description=$1" -d "priority=0" "https://www.notifymyandroid.com/publicapi/notify" -o "$out" - -if test $(xml sel -t -m "nma/success" -v "@code" "$out") == "200"; then - echo "Sent" - exit 0 -fi - -echo "Not sent: $(xml sel -t -m "nma/error" -v "." "$out")" -exit 1 diff --git a/bin/revolver b/bin/revolver index 51c3dba..75f1955 100755 --- a/bin/revolver +++ b/bin/revolver @@ -265,7 +265,7 @@ function _revolver_demo() { # Handle command input ### function _revolver() { - # Get the context from the first parameter + # Get the context from the first parameter local help version style ctx="$1" # Parse CLI options diff --git a/bin/shml b/bin/shml index 2e3a807..ad4b6e5 100755 --- a/bin/shml +++ b/bin/shml @@ -3,13 +3,129 @@ #SHML:START #************************************************# # SHML - Shell Markup Language Framework -# v1.0.3 +# v1.1.0 # (MIT) # by Justin Dorfman - @jdorfman # && Joshua Mervine - @mervinej # -# https://maxcdn.github.io/shml/ +# 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) ## @@ -18,7 +134,7 @@ fgcolor() { local __color=$__end # end by default case "$1" in end|off|reset) __color=$__end;; - black|000000) __color='\033[30m';; + black|000000|000) __color='\033[30m';; red|F00BAF) __color='\033[31m';; green|00CD00) __color='\033[32m';; yellow|CDCD00) __color='\033[33m';; @@ -32,7 +148,7 @@ fgcolor() { lightblue|3a80b5) __color='\033[94m';; lightmagenta|fe00fe) __color='\033[95m';; lightcyan|00fefe) __color='\033[96m';; - white|ffffff) __color='\033[97m';; + white|ffffff|fff) __color='\033[97m';; esac if test "$2"; then echo -en "$__color$2$__end" @@ -62,7 +178,7 @@ bgcolor() { local __color=$__end # end by default case "$1" in end|off|reset) __color=$__end;; - black|000000) __color='\033[40m';; + black|000000|000) __color='\033[40m';; red|F00BAF) __color='\033[41m';; green|00CD00) __color='\033[42m';; yellow|CDCD00) __color='\033[43m';; @@ -77,7 +193,7 @@ bgcolor() { lightblue|3a80b5) __color='\033[104m';; lightmagenta|fe00fe) __color='\033[105m';; lightcyan|00fefe) __color='\033[106m';; - white|fffff) __color='\033[107m';; + white|fffff|fff) __color='\033[107m';; esac if test "$2"; then @@ -158,8 +274,9 @@ tab() { indent() { local __len=4 + local __int='^[0-9]+$' if test "$1"; then - if [[ $1 =~ $re ]] ; then + if [[ $1 =~ $__int ]] ; then __len=$1 fi fi @@ -168,6 +285,7 @@ indent() { __len=$(( $__len - 1 )) done } + i() { indent "$@" } @@ -175,9 +293,9 @@ i() { hr() { local __len=60 local __char='-' + local __int='^[0-9]+$' if ! test "$2"; then - re='^[0-9]+$' - if [[ $1 =~ $re ]] ; then + if [[ $1 =~ $__int ]] ; then __len=$1 elif test "$1"; then __char=$1 @@ -194,7 +312,6 @@ hr() { # Icons ## - icon() { local i=''; case "$1" in @@ -214,59 +331,56 @@ icon() { apple) i='\xEF\xA3\xBF';; skull|bones) i='\xE2\x98\xA0';; ':-)'|':)'|smile|face) i='\xE2\x98\xBA';; - *) - entity $1; return 0;; 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) 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|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='🍀';; - - *) - #entity $1; return 0;; + 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" } @@ -280,9 +394,26 @@ function e { # Usage / Examples ## -if [[ "$(basename -- "$0")" = "shml.sh" ]]; then +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 '=') @@ -484,6 +615,73 @@ $(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 diff --git a/cfg/ssh/cfg b/cfg/ssh/cfg index 88d0f35..7c524cc 100644 --- a/cfg/ssh/cfg +++ b/cfg/ssh/cfg @@ -3,6 +3,6 @@ Host web HostName megumi.eeleater.org User eeleater -Host git - HostName git.eeleater.org +Host ipa + HostName 192.168.122.15 User eeleater diff --git a/cfg/zsh/cfg.d/export.zsh b/cfg/zsh/cfg.d/export.zsh index 9541d0c..e3c8605 100644 --- a/cfg/zsh/cfg.d/export.zsh +++ b/cfg/zsh/cfg.d/export.zsh @@ -41,8 +41,12 @@ fpath+=(${brewpr}/share/zsh/site-functions) fpath+=(${dotlib}/local) fpath+=(${BASHER_ROOT}/cellar/completions/zsh) +# IPFS +IPFS_PATH=/var/lib/ipfs/repo +VAULT_ADDR=http://127.0.0.1:8200 + # Actually export -export dotlib dotcfg brewpr gembin PATH MANPATH INFOPATH EDITOR XDG_DATA_DIRS PTOOLSPATH +export dotlib dotcfg brewpr gembin PATH MANPATH INFOPATH EDITOR XDG_DATA_DIRS PTOOLSPATH IPFSPATH VAULT_ADDR # Reload all Prompts autoload -U promptinit && promptinit diff --git a/cfg/zsh/cfg.d/ohmy.zsh b/cfg/zsh/cfg.d/ohmy.zsh index a02865f..f8eafbc 100644 --- a/cfg/zsh/cfg.d/ohmy.zsh +++ b/cfg/zsh/cfg.d/ohmy.zsh @@ -1,3 +1,4 @@ export ZSH="${dotlib}/ohmyzsh" DISABLE_AUTO_UPDATE="true" +ZSH_DISABLE_COMPFIX="true" source ${ZSH}/oh-my-zsh.sh diff --git a/lib/completions b/lib/completions index df7e44c..09ab969 160000 --- a/lib/completions +++ b/lib/completions @@ -1 +1 @@ -Subproject commit df7e44c685c9a60d83a3760aa373d3864779aeeb +Subproject commit 09ab969e206b4c8984cacd588b18676f7f5109aa diff --git a/lib/gitignore b/lib/gitignore index 318f8fc..72190ee 160000 --- a/lib/gitignore +++ b/lib/gitignore @@ -1 +1 @@ -Subproject commit 318f8fc99146275e0828737ac2898930c6d8342f +Subproject commit 72190ee30bd1e2ccc233222341435adacb7a6500 diff --git a/lib/has b/lib/has index 5443d4c..75ccc96 160000 --- a/lib/has +++ b/lib/has @@ -1 +1 @@ -Subproject commit 5443d4cb9e03d8d97fa0be19a4718958bf23fca4 +Subproject commit 75ccc961718cf51be95644258f97f4c99fdd29e6 diff --git a/lib/ohmyzsh b/lib/ohmyzsh index 652356b..08f2fc1 160000 --- a/lib/ohmyzsh +++ b/lib/ohmyzsh @@ -1 +1 @@ -Subproject commit 652356b9b99b26317478a8756893f896abbed6cd +Subproject commit 08f2fc12143175d011d69189679b0ed4c834b5c7