From 005541a96f1f6d651a5886aacb2b00455e9ed80d Mon Sep 17 00:00:00 2001 From: Nikolas Weger Date: Sun, 10 Nov 2019 13:03:14 +0100 Subject: [PATCH] cleanup for new folder --- .gitmodules | 18 - README.md | 13 - bin/ansi | 1633 ---------- bin/desk | 340 -- bin/hosts | 41 - bin/is | 133 - bin/lj | 156 - bin/mo | 1061 ------- bin/notify | 21 - bin/revolver | 318 -- bin/shml | 688 ---- cfg/dir/cfg | 309 -- cfg/dotbot/cfg | 7 - cfg/git/cfg | 101 - cfg/git/gitignore_global | 31 - cfg/ssh/cfg | 4 - cfg/tmux/tmux.extra.conf | 2 - cfg/tmux/tmux.only.conf | 1 - cfg/zsh/cfg.d/export.zsh | 49 - cfg/zsh/cfg.d/ohmy.zsh | 4 - cfg/zsh/cfg.d/source.d/00-highlighting.zsh | 173 -- cfg/zsh/cfg.d/source.d/01-autosuggest.zsh | 467 --- cfg/zsh/cfg.d/source.d/alias-brew.zsh | 4 - cfg/zsh/cfg.d/source.d/alias-os.zsh | 219 -- cfg/zsh/cfg.d/source.d/alias-systemd.zsh | 8 - cfg/zsh/cfg.d/source.d/function-cnf.zsh | 1 - cfg/zsh/cfg.d/source.d/function-dircolors.zsh | 1 - cfg/zsh/cfg.d/source.d/function-extract.zsh | 72 - cfg/zsh/cfg.d/source.d/function-fzf.zsh | 4 - cfg/zsh/cfg.d/source.d/function-gitignore.zsh | 53 - cfg/zsh/cfg.d/source.d/function-tmux.zsh | 63 - cfg/zsh/cfg.d/source.d/function-workfix.zsh | 3 - cfg/zsh/cfg.d/source.zsh | 10 - cfg/zsh/cfg.zsh | 7 - install | 6 - lib/basher | 1 - lib/completions | 1 - lib/dotbot | 1 - lib/gitignore | 1 - lib/has | 1 - lib/highlight | 715 ----- lib/local/_desk | 34 - lib/local/_docker | 2755 ----------------- lib/local/_docker-compose | 456 --- lib/local/_extract | 8 - lib/local/_lj | 61 - lib/local/_revolver | 34 - lib/local/_vagrant | 131 - lib/local/prompt_z4rr3t_setup | 135 - lib/ohmyzsh | 1 - 50 files changed, 10356 deletions(-) delete mode 100644 README.md delete mode 100755 bin/ansi delete mode 100755 bin/desk delete mode 100755 bin/hosts delete mode 100755 bin/is delete mode 100755 bin/lj delete mode 100755 bin/mo delete mode 100755 bin/notify delete mode 100755 bin/revolver delete mode 100755 bin/shml delete mode 100644 cfg/dir/cfg delete mode 100644 cfg/dotbot/cfg delete mode 100644 cfg/git/cfg delete mode 100644 cfg/git/gitignore_global delete mode 100644 cfg/ssh/cfg delete mode 100644 cfg/tmux/tmux.extra.conf delete mode 100644 cfg/tmux/tmux.only.conf delete mode 100644 cfg/zsh/cfg.d/export.zsh delete mode 100644 cfg/zsh/cfg.d/ohmy.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/00-highlighting.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/01-autosuggest.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/alias-brew.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/alias-os.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/alias-systemd.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/function-cnf.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/function-dircolors.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/function-extract.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/function-fzf.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/function-gitignore.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/function-tmux.zsh delete mode 100644 cfg/zsh/cfg.d/source.d/function-workfix.zsh delete mode 100644 cfg/zsh/cfg.d/source.zsh delete mode 100644 cfg/zsh/cfg.zsh delete mode 100755 install delete mode 160000 lib/basher delete mode 160000 lib/completions delete mode 160000 lib/dotbot delete mode 160000 lib/gitignore delete mode 160000 lib/has delete mode 100644 lib/highlight delete mode 100644 lib/local/_desk delete mode 100644 lib/local/_docker delete mode 100644 lib/local/_docker-compose delete mode 100644 lib/local/_extract delete mode 100644 lib/local/_lj delete mode 100644 lib/local/_revolver delete mode 100644 lib/local/_vagrant delete mode 100644 lib/local/prompt_z4rr3t_setup delete mode 160000 lib/ohmyzsh diff --git a/.gitmodules b/.gitmodules index 8e3dd10..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,18 +0,0 @@ -[submodule "dotbot"] - path = lib/dotbot - url = https://github.com/anishathalye/dotbot -[submodule "lib/completions"] - path = lib/completions - url = https://github.com/zsh-users/zsh-completions -[submodule "lib/ohmyzsh"] - path = lib/ohmyzsh - url = https://github.com/robbyrussell/oh-my-zsh -[submodule "lib/gitignore"] - path = lib/gitignore - url = https://github.com/github/gitignore -[submodule "lib/basher"] - path = lib/basher - url = https://github.com/basherpm/basher -[submodule "lib/has"] - path = lib/has - url = https://github.com/kdabir/has diff --git a/README.md b/README.md deleted file mode 100644 index 2b262a1..0000000 --- a/README.md +++ /dev/null @@ -1,13 +0,0 @@ -## My Dotfiles - - -This Repo contains my dotfiles - -Prerequisites: -- xmlstarlet: `yaourt -S xmlstarlet` -- nano-syntax-highlighting `yaourt -S nano-syntax-highlighting` -- as root `echo "include /usr/share/nano-syntax-highlighting/*.nanorc" >> /etc/nanorc` -- fzf nano-syntax-highlighting `yaourt -S fzf` -- linuxbrew `ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install)"` - -Install with the `./install` script. diff --git a/bin/ansi b/bin/ansi deleted file mode 100755 index a728e5a..0000000 --- a/bin/ansi +++ /dev/null @@ -1,1633 +0,0 @@ -#!/usr/bin/env bash -# -# ANSI code generator -# -# © Copyright 2015 Tyler Akins -# Licensed under the MIT license with an additional non-advertising clause -# See http://github.com/fidian/ansi - -ANSI_ESC=$'\033' -ANSI_CSI="${ANSI_ESC}[" -ANSI_OSC="${ANSI_ESC}]" -ANSI_ST="${ANSI_ESC}\\" -ANSI_REPORT="" # The return value from ansi::report - -ansi::backward() { - printf '%s%sD' "$ANSI_CSI" "${1-}" -} - -ansi::bell() { - printf "%s" $'\007' -} - -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 colorLabel counter fnbLower fnbUpper functionName IFS resetFunction - - 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 <" to enable the override. - if [[ -n "${ANSI_FORCE_SUPPORT-}" ]]; then - return 0 - fi - - if hash tput &> /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, 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 report - - # 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 - return 1 - fi - - 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" - 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() { - cat < [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 '' - $PROGRAM run ... - 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 diff --git a/bin/hosts b/bin/hosts deleted file mode 100755 index 30c80fd..0000000 --- a/bin/hosts +++ /dev/null @@ -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 -} - -$@ diff --git a/bin/is b/bin/is deleted file mode 100755 index bd069b3..0000000 --- a/bin/is +++ /dev/null @@ -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 - diff --git a/bin/lj b/bin/lj deleted file mode 100755 index 5da2112..0000000 --- a/bin/lj +++ /dev/null @@ -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] [] " - 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 "$@" - diff --git a/bin/mo b/bin/mo deleted file mode 100755 index 3015011..0000000 --- a/bin/mo +++ /dev/null @@ -1,1061 +0,0 @@ -#!/usr/bin/env bash -# -#/ Mo is a mustache template rendering software written in bash. It inserts -#/ environment variables into templates. -#/ -#/ Simply put, mo will change {{VARIABLE}} into the value of that -#/ environment variable. You can use {{#VARIABLE}}content{{/VARIABLE}} to -#/ conditionally display content or iterate over the values of an array. -#/ -#/ Learn more about mustache templates at https://mustache.github.io/ -#/ -#/ Simple usage: -#/ -#/ mo [OPTIONS] filenames... -#/ -#/ Options: -#/ -#/ -u, --fail-not-set -#/ - Fail upon expansion of an unset variable. -#/ -e, --false -#/ - Treat the string "false" as empty for conditionals. -#/ -h, --help -#/ - This message. -#/ -s=FILE, --source=FILE -#/ - Load FILE into the environment before processing templates. -# -# Mo is under a MIT style licence with an additional non-advertising clause. -# See LICENSE.md for the full text. -# -# This is open source! Please feel free to contribute. -# -# https://github.com/tests-always-included/mo - - -# Public: Template parser function. Writes templates to stdout. -# -# $0 - Name of the mo file, used for getting the help message. -# --allow-function-arguments -# - Permit functions in templates to be called with additional -# arguments. This puts template data directly in to the path -# of an eval statement. Use with caution. Not listed in the -# help because it only makes sense when mo is sourced. -# -u, --fail-not-set -# - Fail upon expansion of an unset variable. Default behavior -# is to silently ignore and expand into empty string. -# -e, --false - Treat "false" as an empty value. You may set the -# MO_FALSE_IS_EMPTY environment variable instead to a non-empty -# value to enable this behavior. -# -h, --help - Display a help message. -# -s=FILE, --source=FILE -# - Source a file into the environment before processint -# template files. -# -- - Used to indicate the end of options. You may optionally -# use this when filenames may start with two hyphens. -# $@ - Filenames to parse. -# -# Mo uses the following environment variables: -# -# MO_ALLOW_FUNCTION_ARGUMENTS -# - When set to a non-empty value, this allows functions -# referenced in templates to receive additional -# options and arguments. This puts the content from the -# template directly into an eval statement. Use with -# extreme care. -# MO_FUNCTION_ARGS - Arguments passed to the function -# MO_FAIL_ON_UNSET - When set to a non-empty value, expansion of an unset -# env variable will be aborted with an error. -# MO_FALSE_IS_EMPTY - When set to a non-empty value, the string "false" -# will be treated as an empty value for the purposes -# of conditionals. -# MO_ORIGINAL_COMMAND - Used to find the `mo` program in order to generate -# a help message. -# -# Returns nothing. -mo() ( - # This function executes in a subshell so IFS is reset. - # Namespace this variable so we don't conflict with desired values. - local moContent f2source files doubleHyphens - - IFS=$' \n\t' - files=() - doubleHyphens=false - - if [[ $# -gt 0 ]]; then - for arg in "$@"; do - if $doubleHyphens; then - # After we encounter two hyphens together, all the rest - # of the arguments are files. - files=("${files[@]}" "$arg") - else - case "$arg" in - -h|--h|--he|--hel|--help|-\?) - moUsage "$0" - exit 0 - ;; - - --allow-function-arguments) - # shellcheck disable=SC2030 - MO_ALLOW_FUNCTION_ARGUMENTS=true - ;; - - -u | --fail-not-set) - # shellcheck disable=SC2030 - MO_FAIL_ON_UNSET=true - ;; - - -e | --false) - # shellcheck disable=SC2030 - MO_FALSE_IS_EMPTY=true - ;; - - -s=* | --source=*) - if [[ "$arg" == --source=* ]]; then - f2source="${arg#--source=}" - else - f2source="${arg#-s=}" - fi - - if [[ -f "$f2source" ]]; then - # shellcheck disable=SC1090 - . "$f2source" - else - echo "No such file: $f2source" >&2 - exit 1 - fi - ;; - - --) - # Set a flag indicating we've encountered double hyphens - doubleHyphens=true - ;; - - *) - # Every arg that is not a flag or a option should be a file - files=(${files[@]+"${files[@]}"} "$arg") - ;; - esac - fi - done - fi - - moGetContent moContent "${files[@]}" || return 1 - moParse "$moContent" "" true -) - - -# Internal: Call a function. -# -# $1 - Function to call -# $2 - Content to pass -# $3 - Additional arguments as a single string -# -# This can be dangerous, especially if you are using tags like -# {{someFunction ; rm -rf / }} -# -# Returns nothing. -moCallFunction() { - local moArgs moFunctionArgs - - moArgs=() - moTrimWhitespace moFunctionArgs "$3" - - # shellcheck disable=SC2031 - if [[ -n "${MO_ALLOW_FUNCTION_ARGUMENTS-}" ]]; then - moArgs=$3 - fi - - echo -n "$2" | MO_FUNCTION_ARGS="$moFunctionArgs" eval "$1" "$moArgs" -} - - -# Internal: Scan content until the right end tag is found. Creates an array -# with the following members: -# -# [0] = Content before end tag -# [1] = End tag (complete tag) -# [2] = Content after end tag -# -# Everything using this function uses the "standalone tags" logic. -# -# $1 - Name of variable for the array -# $2 - Content -# $3 - Name of end tag -# $4 - If -z, do standalone tag processing before finishing -# -# Returns nothing. -moFindEndTag() { - local content remaining scanned standaloneBytes tag - - #: Find open tags - scanned="" - moSplit content "$2" '{{' '}}' - - while [[ "${#content[@]}" -gt 1 ]]; do - moTrimWhitespace tag "${content[1]}" - - #: Restore content[1] before we start using it - content[1]='{{'"${content[1]}"'}}' - - case $tag in - '#'* | '^'*) - #: Start another block - scanned="${scanned}${content[0]}${content[1]}" - moTrimWhitespace tag "${tag:1}" - moFindEndTag content "${content[2]}" "$tag" "loop" - scanned="${scanned}${content[0]}${content[1]}" - remaining=${content[2]} - ;; - - '/'*) - #: End a block - could be ours - moTrimWhitespace tag "${tag:1}" - scanned="$scanned${content[0]}" - - if [[ "$tag" == "$3" ]]; then - #: Found our end tag - if [[ -z "${4-}" ]] && moIsStandalone standaloneBytes "$scanned" "${content[2]}" true; then - #: This is also a standalone tag - clean up whitespace - #: and move those whitespace bytes to the "tag" element - standaloneBytes=( $standaloneBytes ) - content[1]="${scanned:${standaloneBytes[0]}}${content[1]}${content[2]:0:${standaloneBytes[1]}}" - scanned="${scanned:0:${standaloneBytes[0]}}" - content[2]="${content[2]:${standaloneBytes[1]}}" - fi - - local "$1" && moIndirectArray "$1" "$scanned" "${content[1]}" "${content[2]}" - return 0 - fi - - scanned="$scanned${content[1]}" - remaining=${content[2]} - ;; - - *) - #: Ignore all other tags - scanned="${scanned}${content[0]}${content[1]}" - remaining=${content[2]} - ;; - esac - - moSplit content "$remaining" '{{' '}}' - done - - #: Did not find our closing tag - scanned="$scanned${content[0]}" - local "$1" && moIndirectArray "$1" "${scanned}" "" "" -} - - -# Internal: Find the first index of a substring. If not found, sets the -# index to -1. -# -# $1 - Destination variable for the index -# $2 - Haystack -# $3 - Needle -# -# Returns nothing. -moFindString() { - local pos string - - string=${2%%$3*} - [[ "$string" == "$2" ]] && pos=-1 || pos=${#string} - local "$1" && moIndirect "$1" "$pos" -} - - -# Internal: Generate a dotted name based on current context and target name. -# -# $1 - Target variable to store results -# $2 - Context name -# $3 - Desired variable name -# -# Returns nothing. -moFullTagName() { - if [[ -z "${2-}" ]] || [[ "$2" == *.* ]]; then - local "$1" && moIndirect "$1" "$3" - else - local "$1" && moIndirect "$1" "${2}.${3}" - fi -} - - -# Internal: Fetches the content to parse into a variable. Can be a list of -# partials for files or the content from stdin. -# -# $1 - Variable name to assign this content back as -# $2-@ - File names (optional) -# -# Returns nothing. -moGetContent() { - local content filename target - - target=$1 - shift - if [[ "${#@}" -gt 0 ]]; then - content="" - - for filename in "$@"; do - #: This is so relative paths work from inside template files - content="$content"'{{>'"$filename"'}}' - done - else - moLoadFile content /dev/stdin || return 1 - fi - - local "$target" && moIndirect "$target" "$content" -} - - -# Internal: Indent a string, placing the indent at the beginning of every -# line that has any content. -# -# $1 - Name of destination variable to get an array of lines -# $2 - The indent string -# $3 - The string to reindent -# -# Returns nothing. -moIndentLines() { - local content fragment len posN posR result trimmed - - result="" - - #: Remove the period from the end of the string. - len=$((${#3} - 1)) - content=${3:0:$len} - - if [[ -z "${2-}" ]]; then - local "$1" && moIndirect "$1" "$content" - - return 0 - fi - - moFindString posN "$content" $'\n' - moFindString posR "$content" $'\r' - - while [[ "$posN" -gt -1 ]] || [[ "$posR" -gt -1 ]]; do - if [[ "$posN" -gt -1 ]]; then - fragment="${content:0:$posN + 1}" - content=${content:$posN + 1} - else - fragment="${content:0:$posR + 1}" - content=${content:$posR + 1} - fi - - moTrimChars trimmed "$fragment" false true " " $'\t' $'\n' $'\r' - - if [[ -n "$trimmed" ]]; then - fragment="$2$fragment" - fi - - result="$result$fragment" - - moFindString posN "$content" $'\n' - moFindString posR "$content" $'\r' - - # If the content ends in a newline, do not indent. - if [[ "$posN" -eq ${#content} ]]; then - # Special clause for \r\n - if [[ "$posR" -eq "$((posN - 1))" ]]; then - posR=-1 - fi - - posN=-1 - fi - - if [[ "$posR" -eq ${#content} ]]; then - posR=-1 - fi - done - - moTrimChars trimmed "$content" false true " " $'\t' - - if [[ -n "$trimmed" ]]; then - content="$2$content" - fi - - result="$result$content" - - local "$1" && moIndirect "$1" "$result" -} - - -# Internal: Send a variable up to the parent of the caller of this function. -# -# $1 - Variable name -# $2 - Value -# -# Examples -# -# callFunc () { -# local "$1" && moIndirect "$1" "the value" -# } -# callFunc dest -# echo "$dest" # writes "the value" -# -# Returns nothing. -moIndirect() { - unset -v "$1" - printf -v "$1" '%s' "$2" -} - - -# Internal: Send an array as a variable up to caller of a function -# -# $1 - Variable name -# $2-@ - Array elements -# -# Examples -# -# callFunc () { -# local myArray=(one two three) -# local "$1" && moIndirectArray "$1" "${myArray[@]}" -# } -# callFunc dest -# echo "${dest[@]}" # writes "one two three" -# -# Returns nothing. -moIndirectArray() { - unset -v "$1" - - # IFS must be set to a string containing space or unset in order for - # the array slicing to work regardless of the current IFS setting on - # bash 3. This is detailed further at - # https://github.com/fidian/gg-core/pull/7 - eval "$(printf "IFS= %s=(\"\${@:2}\") IFS=%q" "$1" "$IFS")" -} - - -# Internal: Determine if a given environment variable exists and if it is -# an array. -# -# $1 - Name of environment variable -# -# Be extremely careful. Even if strict mode is enabled, it is not honored -# in newer versions of Bash. Any errors that crop up here will not be -# caught automatically. -# -# Examples -# -# var=(abc) -# if moIsArray var; then -# echo "This is an array" -# echo "Make sure you don't accidentally use \$var" -# fi -# -# Returns 0 if the name is not empty, 1 otherwise. -moIsArray() { - # Namespace this variable so we don't conflict with what we're testing. - local moTestResult - - moTestResult=$(declare -p "$1" 2>/dev/null) || return 1 - [[ "${moTestResult:0:10}" == "declare -a" ]] && return 0 - [[ "${moTestResult:0:10}" == "declare -A" ]] && return 0 - - return 1 -} - - -# Internal: Determine if the given name is a defined function. -# -# $1 - Function name to check -# -# Be extremely careful. Even if strict mode is enabled, it is not honored -# in newer versions of Bash. Any errors that crop up here will not be -# caught automatically. -# -# Examples -# -# moo () { -# echo "This is a function" -# } -# if moIsFunction moo; then -# echo "moo is a defined function" -# fi -# -# Returns 0 if the name is a function, 1 otherwise. -moIsFunction() { - local functionList functionName - - functionList=$(declare -F) - functionList=( ${functionList//declare -f /} ) - - for functionName in "${functionList[@]}"; do - if [[ "$functionName" == "$1" ]]; then - return 0 - fi - done - - return 1 -} - - -# Internal: Determine if the tag is a standalone tag based on whitespace -# before and after the tag. -# -# Passes back a string containing two numbers in the format "BEFORE AFTER" -# like "27 10". It indicates the number of bytes remaining in the "before" -# string (27) and the number of bytes to trim in the "after" string (10). -# Useful for string manipulation: -# -# $1 - Variable to set for passing data back -# $2 - Content before the tag -# $3 - Content after the tag -# $4 - true/false: is this the beginning of the content? -# -# Examples -# -# moIsStandalone RESULT "$before" "$after" false || return 0 -# RESULT_ARRAY=( $RESULT ) -# echo "${before:0:${RESULT_ARRAY[0]}}...${after:${RESULT_ARRAY[1]}}" -# -# Returns nothing. -moIsStandalone() { - local afterTrimmed beforeTrimmed char - - moTrimChars beforeTrimmed "$2" false true " " $'\t' - moTrimChars afterTrimmed "$3" true false " " $'\t' - char=$((${#beforeTrimmed} - 1)) - char=${beforeTrimmed:$char} - - # If the content before didn't end in a newline - if [[ "$char" != $'\n' ]] && [[ "$char" != $'\r' ]]; then - # and there was content or this didn't start the file - if [[ -n "$char" ]] || ! $4; then - # then this is not a standalone tag. - return 1 - fi - fi - - char=${afterTrimmed:0:1} - - # If the content after doesn't start with a newline and it is something - if [[ "$char" != $'\n' ]] && [[ "$char" != $'\r' ]] && [[ -n "$char" ]]; then - # then this is not a standalone tag. - return 2 - fi - - if [[ "$char" == $'\r' ]] && [[ "${afterTrimmed:1:1}" == $'\n' ]]; then - char="$char"$'\n' - fi - - local "$1" && moIndirect "$1" "$((${#beforeTrimmed})) $((${#3} + ${#char} - ${#afterTrimmed}))" -} - - -# Internal: Join / implode an array -# -# $1 - Variable name to receive the joined content -# $2 - Joiner -# $3-$* - Elements to join -# -# Returns nothing. -moJoin() { - local joiner part result target - - target=$1 - joiner=$2 - result=$3 - shift 3 - - for part in "$@"; do - result="$result$joiner$part" - done - - local "$target" && moIndirect "$target" "$result" -} - - -# Internal: Read a file into a variable. -# -# $1 - Variable name to receive the file's content -# $2 - Filename to load -# -# Returns nothing. -moLoadFile() { - local content len - - # The subshell removes any trailing newlines. We forcibly add - # a dot to the content to preserve all newlines. - # As a future optimization, it would be worth considering removing - # cat and replacing this with a read loop. - - content=$(cat -- "$2" && echo '.') || return 1 - len=$((${#content} - 1)) - content=${content:0:$len} # Remove last dot - - local "$1" && moIndirect "$1" "$content" -} - - -# Internal: Process a chunk of content some number of times. Writes output -# to stdout. -# -# $1 - Content to parse repeatedly -# $2 - Tag prefix (context name) -# $3-@ - Names to insert into the parsed content -# -# Returns nothing. -moLoop() { - local content context contextBase - - content=$1 - contextBase=$2 - shift 2 - - while [[ "${#@}" -gt 0 ]]; do - moFullTagName context "$contextBase" "$1" - moParse "$content" "$context" false - shift - done -} - - -# Internal: Parse a block of text, writing the result to stdout. -# -# $1 - Block of text to change -# $2 - Current name (the variable NAME for what {{.}} means) -# $3 - true when no content before this, false otherwise -# -# Returns nothing. -moParse() { - # Keep naming variables mo* here to not overwrite needed variables - # used in the string replacements - local moArgs moBlock moContent moCurrent moIsBeginning moNextIsBeginning moTag - - moCurrent=$2 - moIsBeginning=$3 - - # Find open tags - moSplit moContent "$1" '{{' '}}' - - while [[ "${#moContent[@]}" -gt 1 ]]; do - moTrimWhitespace moTag "${moContent[1]}" - moNextIsBeginning=false - - case $moTag in - '#'*) - # Loop, if/then, or pass content through function - # Sets context - moStandaloneAllowed moContent "${moContent[@]}" "$moIsBeginning" - moTrimWhitespace moTag "${moTag:1}" - - # Split arguments from the tag name. Arguments are passed to - # functions. - moArgs=$moTag - moTag=${moTag%% *} - moTag=${moTag%%$'\t'*} - moArgs=${moArgs:${#moTag}} - moFindEndTag moBlock "$moContent" "$moTag" - moFullTagName moTag "$moCurrent" "$moTag" - - if moTest "$moTag"; then - # Show / loop / pass through function - if moIsFunction "$moTag"; then - #: Consider piping the output to moGetContent - #: so the lambda does not execute in a subshell? - moContent=$(moCallFunction "$moTag" "${moBlock[0]}" "$moArgs") - moParse "$moContent" "$moCurrent" false - moContent="${moBlock[2]}" - elif moIsArray "$moTag"; then - eval "moLoop \"\${moBlock[0]}\" \"$moTag\" \"\${!${moTag}[@]}\"" - else - moParse "${moBlock[0]}" "$moCurrent" true - fi - fi - - moContent="${moBlock[2]}" - ;; - - '>'*) - # Load partial - get name of file relative to cwd - moPartial moContent "${moContent[@]}" "$moIsBeginning" "$moCurrent" - moNextIsBeginning=${moContent[1]} - moContent=${moContent[0]} - ;; - - '/'*) - # Closing tag - If hit in this loop, we simply ignore - # Matching tags are found in moFindEndTag - moStandaloneAllowed moContent "${moContent[@]}" "$moIsBeginning" - ;; - - '^'*) - # Display section if named thing does not exist - moStandaloneAllowed moContent "${moContent[@]}" "$moIsBeginning" - moTrimWhitespace moTag "${moTag:1}" - moFindEndTag moBlock "$moContent" "$moTag" - moFullTagName moTag "$moCurrent" "$moTag" - - if ! moTest "$moTag"; then - moParse "${moBlock[0]}" "$moCurrent" false "$moCurrent" - fi - - moContent="${moBlock[2]}" - ;; - - '!'*) - # Comment - ignore the tag content entirely - # Trim spaces/tabs before the comment - moStandaloneAllowed moContent "${moContent[@]}" "$moIsBeginning" - ;; - - .) - # Current content (environment variable or function) - moStandaloneDenied moContent "${moContent[@]}" - moShow "$moCurrent" "$moCurrent" - ;; - - '=') - # Change delimiters - # Any two non-whitespace sequences separated by whitespace. - # This tag is ignored. - moStandaloneAllowed moContent "${moContent[@]}" "$moIsBeginning" - ;; - - '{'*) - # Unescaped - split on }}} not }} - moStandaloneDenied moContent "${moContent[@]}" - moContent="${moTag:1}"'}}'"$moContent" - moSplit moContent "$moContent" '}}}' - moTrimWhitespace moTag "${moContent[0]}" - moArgs=$moTag - moTag=${moTag%% *} - moTag=${moTag%%$'\t'*} - moArgs=${moArgs:${#moTag}} - moFullTagName moTag "$moCurrent" "$moTag" - moContent=${moContent[1]} - - # Now show the value - # Quote moArgs here, do not quote it later. - moShow "$moTag" "$moCurrent" "$moArgs" - ;; - - '&'*) - # Unescaped - moStandaloneDenied moContent "${moContent[@]}" - moTrimWhitespace moTag "${moTag:1}" - moFullTagName moTag "$moCurrent" "$moTag" - moShow "$moTag" "$moCurrent" - ;; - - *) - # Normal environment variable or function call - moStandaloneDenied moContent "${moContent[@]}" - moArgs=$moTag - moTag=${moTag%% *} - moTag=${moTag%%$'\t'*} - moArgs=${moArgs:${#moTag}} - moFullTagName moTag "$moCurrent" "$moTag" - - # Quote moArgs here, do not quote it later. - moShow "$moTag" "$moCurrent" "$moArgs" - ;; - esac - - moIsBeginning=$moNextIsBeginning - moSplit moContent "$moContent" '{{' '}}' - done - - echo -n "${moContent[0]}" -} - - -# Internal: Process a partial. -# -# Indentation should be applied to the entire partial. -# -# This sends back the "is beginning" flag because the newline after a -# standalone partial is consumed. That newline is very important in the middle -# of content. We send back this flag to reset the processing loop's -# `moIsBeginning` variable, so the software thinks we are back at the -# beginning of a file and standalone processing continues to work. -# -# Prefix all variables. -# -# $1 - Name of destination variable. Element [0] is the content, [1] is the -# true/false flag indicating if we are at the beginning of content. -# $2 - Content before the tag that was not yet written -# $3 - Tag content -# $4 - Content after the tag -# $5 - true/false: is this the beginning of the content? -# $6 - Current context name -# -# Returns nothing. -moPartial() { - # Namespace variables here to prevent conflicts. - local moContent moFilename moIndent moIsBeginning moPartial moStandalone moUnindented - - if moIsStandalone moStandalone "$2" "$4" "$5"; then - moStandalone=( $moStandalone ) - echo -n "${2:0:${moStandalone[0]}}" - moIndent=${2:${moStandalone[0]}} - moContent=${4:${moStandalone[1]}} - moIsBeginning=true - else - moIndent="" - echo -n "$2" - moContent=$4 - moIsBeginning=$5 - fi - - moTrimWhitespace moFilename "${3:1}" - - # Execute in subshell to preserve current cwd and environment - ( - # It would be nice to remove `dirname` and use a function instead, - # but that's difficult when you're only given filenames. - cd "$(dirname -- "$moFilename")" || exit 1 - moUnindented="$( - moLoadFile moPartial "${moFilename##*/}" || exit 1 - moParse "${moPartial}" "$6" true - - # Fix bash handling of subshells and keep trailing whitespace. - # This is removed in moIndentLines. - echo -n "." - )" || exit 1 - moIndentLines moPartial "$moIndent" "$moUnindented" - echo -n "$moPartial" - ) || exit 1 - - # If this is a standalone tag, the trailing newline after the tag is - # removed and the contents of the partial are added, which typically - # contain a newline. We need to send a signal back to the processing - # loop that the moIsBeginning flag needs to be turned on again. - # - # [0] is the content, [1] is that flag. - local "$1" && moIndirectArray "$1" "$moContent" "$moIsBeginning" -} - - -# Internal: Show an environment variable or the output of a function to -# stdout. -# -# Limit/prefix any variables used. -# -# $1 - Name of environment variable or function -# $2 - Current context -# $3 - Arguments string if $1 is a function -# -# Returns nothing. -moShow() { - # Namespace these variables - local moJoined moNameParts - - if moIsFunction "$1"; then - CONTENT=$(moCallFunction "$1" "" "$3") - moParse "$CONTENT" "$2" false - return 0 - fi - - moSplit moNameParts "$1" "." - - if [[ -z "${moNameParts[1]-}" ]]; then - if moIsArray "$1"; then - eval moJoin moJoined "," "\${$1[@]}" - echo -n "$moJoined" - else - # shellcheck disable=SC2031 - if moTestVarSet "$1"; then - echo -n "${!1}" - elif [[ -n "${MO_FAIL_ON_UNSET-}" ]]; then - echo "Env variable not set: $1" >&2 - exit 1 - fi - fi - else - # Further subindexes are disallowed - eval "echo -n \"\${${moNameParts[0]}[${moNameParts[1]%%.*}]}\"" - fi -} - - -# Internal: Split a larger string into an array. -# -# $1 - Destination variable -# $2 - String to split -# $3 - Starting delimiter -# $4 - Ending delimiter (optional) -# -# Returns nothing. -moSplit() { - local pos result - - result=( "$2" ) - moFindString pos "${result[0]}" "$3" - - if [[ "$pos" -ne -1 ]]; then - # The first delimiter was found - result[1]=${result[0]:$pos + ${#3}} - result[0]=${result[0]:0:$pos} - - if [[ -n "${4-}" ]]; then - moFindString pos "${result[1]}" "$4" - - if [[ "$pos" -ne -1 ]]; then - # The second delimiter was found - result[2]="${result[1]:$pos + ${#4}}" - result[1]="${result[1]:0:$pos}" - fi - fi - fi - - local "$1" && moIndirectArray "$1" "${result[@]}" -} - - -# Internal: Handle the content for a standalone tag. This means removing -# whitespace (not newlines) before a tag and whitespace and a newline after -# a tag. That is, assuming, that the line is otherwise empty. -# -# $1 - Name of destination "content" variable. -# $2 - Content before the tag that was not yet written -# $3 - Tag content (not used) -# $4 - Content after the tag -# $5 - true/false: is this the beginning of the content? -# -# Returns nothing. -moStandaloneAllowed() { - local bytes - - if moIsStandalone bytes "$2" "$4" "$5"; then - bytes=( $bytes ) - echo -n "${2:0:${bytes[0]}}" - local "$1" && moIndirect "$1" "${4:${bytes[1]}}" - else - echo -n "$2" - local "$1" && moIndirect "$1" "$4" - fi -} - - -# Internal: Handle the content for a tag that is never "standalone". No -# adjustments are made for newlines and whitespace. -# -# $1 - Name of destination "content" variable. -# $2 - Content before the tag that was not yet written -# $3 - Tag content (not used) -# $4 - Content after the tag -# -# Returns nothing. -moStandaloneDenied() { - echo -n "$2" - local "$1" && moIndirect "$1" "$4" -} - - -# Internal: Determines if the named thing is a function or if it is a -# non-empty environment variable. When MO_FALSE_IS_EMPTY is set to a -# non-empty value, then "false" is also treated is an empty value. -# -# Do not use variables without prefixes here if possible as this needs to -# check if any name exists in the environment -# -# $1 - Name of environment variable or function -# $2 - Current value (our context) -# MO_FALSE_IS_EMPTY - When set to a non-empty value, this will say the -# string value "false" is empty. -# -# Returns 0 if the name is not empty, 1 otherwise. When MO_FALSE_IS_EMPTY -# is set, this returns 1 if the name is "false". -moTest() { - # Test for functions - moIsFunction "$1" && return 0 - - if moIsArray "$1"; then - # Arrays must have at least 1 element - eval "[[ \"\${#${1}[@]}\" -gt 0 ]]" && return 0 - else - # If MO_FALSE_IS_EMPTY is set, then return 1 if the value of - # the variable is "false". - # shellcheck disable=SC2031 - [[ -n "${MO_FALSE_IS_EMPTY-}" ]] && [[ "${!1-}" == "false" ]] && return 1 - - # Environment variables must not be empty - [[ -n "${!1-}" ]] && return 0 - fi - - return 1 -} - -# Internal: Determine if a variable is assigned, even if it is assigned an empty -# value. -# -# $1 - Variable name to check. -# -# Returns true (0) if the variable is set, 1 if the variable is unset. -moTestVarSet() { - [[ "${!1-a}" == "${!1-b}" ]] -} - - -# Internal: Trim the leading whitespace only. -# -# $1 - Name of destination variable -# $2 - The string -# $3 - true/false - trim front? -# $4 - true/false - trim end? -# $5-@ - Characters to trim -# -# Returns nothing. -moTrimChars() { - local back current front last target varName - - target=$1 - current=$2 - front=$3 - back=$4 - last="" - shift 4 # Remove target, string, trim front flag, trim end flag - - while [[ "$current" != "$last" ]]; do - last=$current - - for varName in "$@"; do - $front && current="${current/#$varName}" - $back && current="${current/%$varName}" - done - done - - local "$target" && moIndirect "$target" "$current" -} - - -# Internal: Trim leading and trailing whitespace from a string. -# -# $1 - Name of variable to store trimmed string -# $2 - The string -# -# Returns nothing. -moTrimWhitespace() { - local result - - moTrimChars result "$2" true true $'\r' $'\n' $'\t' " " - local "$1" && moIndirect "$1" "$result" -} - - -# Internal: Displays the usage for mo. Pulls this from the file that -# contained the `mo` function. Can only work when the right filename -# comes is the one argument, and that only happens when `mo` is called -# with `$0` set to this file. -# -# $1 - Filename that has the help message -# -# 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/notify b/bin/notify deleted file mode 100755 index d1bd311..0000000 --- a/bin/notify +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/php - " - 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 Start the spinner" - echo " update 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 "$@" diff --git a/bin/shml b/bin/shml deleted file mode 100755 index ad4b6e5..0000000 --- a/bin/shml +++ /dev/null @@ -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: diff --git a/cfg/dir/cfg b/cfg/dir/cfg deleted file mode 100644 index bec0c25..0000000 --- a/cfg/dir/cfg +++ /dev/null @@ -1,309 +0,0 @@ -# Configuration file for dircolors, a utility to help you set the -# LS_COLORS environment variable used by GNU ls with the --color option. - -# Copyright (C) 1996, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 -# Free Software Foundation, Inc. -# Copying and distribution of this file, with or without modification, -# are permitted provided the copyright notice and this notice are preserved. -# -# You can copy this file to .dir_colors in your $HOME directory to override -# the system defaults. - -# Below, there should be one TERM entry for each termtype that is colorizable -TERM Eterm -TERM ansi -TERM color-xterm -TERM con132x25 -TERM con132x30 -TERM con132x43 -TERM con132x60 -TERM con80x25 -TERM con80x28 -TERM con80x30 -TERM con80x43 -TERM con80x50 -TERM con80x60 -TERM console -TERM cygwin -TERM dtterm -TERM gnome -TERM konsole -TERM kterm -TERM linux -TERM linux-c -TERM mach-color -TERM mlterm -TERM putty -TERM rxvt -TERM rxvt-cygwin -TERM rxvt-cygwin-native -TERM rxvt-unicode -TERM screen -TERM screen-256color -TERM screen-bce -TERM screen-w -TERM screen.linux -TERM vt100 -TERM xterm -TERM xterm-256color -TERM xterm-color -TERM xterm-debian - -# Special files - -# Below are the color init strings for the basic file types. A color init -# string consists of one or more of the following numeric codes: -# Attribute codes: -# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed -# Text color codes: -# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white -# Background color codes: -# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white -NORMAL 00;37 # global default, although everything should be something. -FILE 01;34 # normal file -RESET 00;37 # reset to "normal" color -DIR 00;34 # directory -LINK 00;36 # symbolic link. (If you set this to 'target' instead of a - # numerical value, the color is as for the file pointed to.) -MULTIHARDLINK 00;37 # regular file with more than one link -FIFO 40;33 # pipe -SOCK 00;35 # socket -DOOR 00;35 # door -BLK 40;33;01 # block device driver -CHR 40;33;01 # character device driver -ORPHAN 00;05;37;41 # orphaned syminks -MISSING 00;05;37;41 # ... and the files they point to -SETUID 37;41 # file that is setuid (u+s) -SETGID 30;43 # file that is setgid (g+s) -CAPABILITY 30;41 # file with capability -STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w) -OTHER_WRITABLE 04;34 # dir that is other-writable (o+w) and not sticky -STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable -EXEC 00;32 # This is for files with execute permission: - -# If you use DOS-style suffixes, you may want to uncomment the following: -.cmd 00;33 # executables (bright green) -.exe 00;33 -.com 00;33 -.btm 00;33 -.bat 00;33 - -## Archives or compressed (red) -.tar 01;31 -.tgz 01;31 -.arj 01;31 -.taz 01;31 -.lzh 01;31 -.lzma 01;31 -.tlz 01;31 -.txz 01;31 -.zip 01;31 -.z 01;31 -.Z 01;31 -.dz 01;31 -.gz 01;31 -.lz 01;31 -.xz 01;31 -.bz 01;31 -.bz2 01;31 -.bzip2 01;31 -.tbz 01;31 -.tbz2 01;31 -.tz 01;31 -.deb 01;31 -.rpm 01;31 -.jar 01;31 -.rar 01;31 # rar -.ace 01;31 # unace -.zoo 01;31 # zoo -.cpio 01;31 # cpio -.7z 01;31 # p7zip -.rz 01;31 # rzip -.apk 01;31 # rzip -.gem 01;31 # rzip - -## image formats (magenta) -.jpg 00;35 -.JPG 00;35 -.jpeg 00;35 -.gif 00;35 -.bmp 00;35 -.pbm 00;35 -.pgm 00;35 -.ppm 00;35 -.tga 00;35 -.xbm 00;35 -.xpm 00;35 -.tif 00;35 -.tiff 00;35 -.png 00;35 -.svg 00;35 -.svgz 00;35 -.mng 00;35 -.pcx 00;35 -.dl 00;35 -.xcf 00;35 -.xwd 00;35 -.yuv 00;35 -.cgm 00;35 -.emf 00;35 -.eps 00;35 -.CR2 00;35 -.ico 00;35 - -## Document files (green) -.pdf 00;32 -.ps 00;32 -.txt 00;32 -.html 00;32 -.rst 00;32 -.md 00;32 -.patch 00;32 -.diff 00;32 -.tex 00;32 -.doc 00;32 -.xml 00;32 -.xls 00;32 -.xlsx 00;32 -.doc 00;32 -.docx 00;32 -.ppt 00;32 -.pptx 00;32 -.key 00;32 # Keynote presentation - -## Template files (bright green) -.pt 01;32 # Zope page template -.tmpl 01;32 -.in 01;32 - -## Audio formats (bright red) -.aac 01;36 -.au 01;36 -.flac 01;36 -.mid 01;36 -.midi 01;36 -.mka 01;36 -.mp3 01;36 -.mpc 01;36 -.ogg 01;36 -.ra 01;36 -.wav 01;36 -.m4a 01;36 -.axa 01;36 -.oga 01;36 -.spx 01;36 -.xspf 01;36 - -## Video formats (as audio + bold) -.mov 01;36 -.mpg 01;36 -.mpeg 01;36 -.m2v 01;36 -.mkv 01;36 -.ogm 01;36 -.mp4 01;36 -.m4v 01;36 -.mp4v 01;36 -.vob 01;36 -.qt 01;36 -.nuv 01;36 -.wmv 01;36 -.asf 01;36 -.rm 01;36 -.rmvb 01;36 -.flc 01;36 -.avi 01;36 -.fli 01;36 -.flv 01;36 -.gl 01;36 -.m2ts 01;36 -.divx 01;36 -.webm 01;36 -.axv 01;36 -.anx 01;36 -.ogv 01;36 -.ogx 01;36 - -## Config files (cyan) -.conf 00;36 -.cnf 00;36 -.cfg 00;36 -.ini 00;36 -.properties 00;36 -.yaml 00;36 -.vcl 00;36 # Varnish - -## Source code files (yellow) -.c 00;33 -.cpp 00;33 -.py 00;33 -.coffesscript 00;33 -.js 00;33 -.rb 00;33 -.sh 00;33 -.zsh 00;33 -.env 00;33 -.bash 00;33 -.php 00;33 -.java 00;33 -.zcml 00;33 # Zope configuration language - -## Data / database (green) -.db 00;32 -.sql 00;32 -.json 00;32 -.plist 00;32 # OSX properties -.fs 00;32 # ZODB Data.fs - -## Files of special interest (base1 + bold) -.tex 01;37 -.rdf 01;37 -.owl 01;37 -.n3 01;37 -.ttl 01;37 -.nt 01;37 -.torrent 01;37 -.xml 01;37 -*Makefile 01;37 -*Rakefile 01;37 -*build.xml 01;37 -*rc 01;37 -.nfo 01;37 -*README 01;37 -*README.txt 01;37 -*readme.txt 01;37 -*README.markdown 01;37 -*README.md 01;37 -.ini 01;37 -.yml 01;37 -.cfg 01;37 -.conf 01;37 -.c 01;37 -.cpp 01;37 -.cc 01;37 - -## Machine generated files / non-important (bright black) -.log 01;30 -.bak 01;30 -.aux 01;30 -.lof 01;30 -.lol 01;30 -.lot 01;30 -.out 01;30 -.toc 01;30 -.bbl 01;30 -.blg 01;30 -*~ 01;30 -*# 01;30 -.part 01;30 -.incomplete 01;30 -.swp 01;30 -.tmp 01;30 -.temp 01;30 -.o 01;30 -.obj 01;30 -.pyc 01;30 -.pyo 01;30 -.class 01;30 -.cache 01;30 -.egg-info 01;30 diff --git a/cfg/dotbot/cfg b/cfg/dotbot/cfg deleted file mode 100644 index 63921fa..0000000 --- a/cfg/dotbot/cfg +++ /dev/null @@ -1,7 +0,0 @@ -- clean: ['~'] - -- link: - ~/.gitconfig: cfg/git/cfg - ~/.zshrc: cfg/zsh/cfg.zsh - ~/.ssh/config: cfg/ssh/cfg - ~/dotfiles/bin/has: lib/has/has diff --git a/cfg/git/cfg b/cfg/git/cfg deleted file mode 100644 index 5e62b42..0000000 --- a/cfg/git/cfg +++ /dev/null @@ -1,101 +0,0 @@ -[user] - email = nikolasweger@googlemail.com - name = Nikolas Weger - -[alias] - exec = ! "exec" - st = status -sb - br = branch -vv - bra = branch -vv --all - bed = branch --edit-description - aa = add --all :/ - ci = commit -v - ca = commit --amend -v - save = commit -a -m "Save" - co = checkout - di = diff - dis = diff --stat - diw = diff --color-words - dic = diff --color-words=. - dc = diff --cached - dcs = diff --cached --stat - dcw = diff --cached --color-words - dcc = diff --cached --color-words=. - dh = diff HEAD~ - dhs = diff HEAD~ --stat - dhw = diff HEAD~ --color-words - dhc = diff HEAD~ --color-words=. - grp = grep -C 1 - ff = merge --ff-only - noff = merge --no-ff - fa = fetch --all - deleted = remote prune --dry-run - prunable = ! "pr() { git remote | xargs -L 1 git deleted; }; pr" - pruneall = ! "pa() { git remote | xargs -L 1 git remote prune; }; pa" - pullff = pull --ff-only - pullrb = pull --rebase - mirror-remote = ! "mr() { git push \"${2}\" \"refs/remotes/${1}/*:refs/heads/*\" && git remote set-head \"${2}\" -a; }; mr" - count = diff --stat "4b825dc642cb6eb9a060e54bf8d69288fbee4904" # hash of empty tree - credit = shortlog -sn - linecredit = ! "lc() { git ls-tree --name-only -z -r HEAD | xargs -0 -n1 git diff --no-index --numstat /dev/null 2>/dev/null | grep -v '^-' | cut -f 3- | cut -d ' ' -f 3- | xargs -n1 git blame --line-porcelain | grep '^author ' | cut -d ' ' -f 2- | sort | uniq -c | sort -nr; }; lc" - cc = rev-list HEAD --count - cca = rev-list --all --count - lg = log -p - gr = log --graph --format=compact # graph - grl = log --graph --format=line # graph line - grd = log --graph --format=detail # graph detail - gra = log --graph --format=compact --all # graph all - gral = log --graph --format=line --all # graph all line - grad = log --graph --format=detail --all # graph all in detail - sf = show --format=fuller - sfs = show --format=fuller --stat - info = ! "inf() { if git rev-parse ${1} >/dev/null 2>&1; then git cat-file -p $(git rev-parse ${1}); else echo Invalid object; fi }; inf" - cleanall = clean -fdx # this is dangerous, so it's intentionally long to type - update-submodules = submodule update --init --recursive - upgrade-submodules = submodule update --init --remote - upgrade-all-submodules = submodule foreach git pull origin master - empty-tree-hash = hash-object -t tree /dev/null - root = rev-parse --show-toplevel - ctags = ! "ctg() { trap \"rm -f .git/tags.$$\" EXIT; ctags --tag-relative -Rf.git/tags.$$ --exclude=.git; mv .git/tags.$$ .git/tags; }; ctg" - tar = ! "tar() { git archive --format tar --prefix=\"${PWD##*/}/\" HEAD -o ${1}; }; tar" - targz = ! "targz() { git archive --format tar.gz --prefix=\"${PWD##*/}/\" HEAD -o ${1}; }; targz" - zip = ! "zip() { git archive --format zip --prefix=\"${PWD##*/}/\" HEAD -o ${1}; }; zip" - -[color] - ui = auto - -[color "grep"] - match = cyan bold - selected = blue - context = normal - filename = magenta - linenumber = green - separator = yellow - function = blue - -[pretty] - line = "%C(auto)%h%d %s %C(yellow)by %C(blue)%an %C(green)%ar" - compact = "%C(auto)%h %s %C(green)%ar%n %C(auto)%d%n" - detail = "%C(auto)%h %s%n %C(yellow)by %C(blue)%an %C(magenta)<%ae> [%G?] %C(green)%ar%n %C(auto)%d%n" - -[merge] - defaultToUpstream = true - tool = vimdiff - -[mergetool] - keepBackup = false - -[push] - default = upstream - -[credential] - helper = cache --timeout=3600 - -[grep] - lineNumber = true - -[advice] - detachedHead = false - -[core] - excludesfile = ~/dotfiles/git/gitignore_global diff --git a/cfg/git/gitignore_global b/cfg/git/gitignore_global deleted file mode 100644 index b9c0cc3..0000000 --- a/cfg/git/gitignore_global +++ /dev/null @@ -1,31 +0,0 @@ -# Compiled source # -################### -*.com -*.class -*.dll -*.exe -*.o -*.so -*.pyc - -# Editing tools and IDEs # -########################## -*.swp -*~ - -# Logs and databases # -###################### -*.log -*.sql -*.sqlite - -# OS generated files # -###################### -.DS_Store -.DS_Store? -._* -.Spotlight-V100 -.Trashes -Icon? -ehthumbs.db -Thumbs.db diff --git a/cfg/ssh/cfg b/cfg/ssh/cfg deleted file mode 100644 index 200ad71..0000000 --- a/cfg/ssh/cfg +++ /dev/null @@ -1,4 +0,0 @@ -Host web - ForwardX11 yes - HostName megumi.eeleater.org - User eeleater diff --git a/cfg/tmux/tmux.extra.conf b/cfg/tmux/tmux.extra.conf deleted file mode 100644 index beffd38..0000000 --- a/cfg/tmux/tmux.extra.conf +++ /dev/null @@ -1,2 +0,0 @@ -set -g default-terminal $ZSH_TMUX_TERM -source $HOME/.tmux.conf diff --git a/cfg/tmux/tmux.only.conf b/cfg/tmux/tmux.only.conf deleted file mode 100644 index 0734df3..0000000 --- a/cfg/tmux/tmux.only.conf +++ /dev/null @@ -1 +0,0 @@ -set -g default-terminal $ZSH_TMUX_TERM diff --git a/cfg/zsh/cfg.d/export.zsh b/cfg/zsh/cfg.d/export.zsh deleted file mode 100644 index e5f7c0b..0000000 --- a/cfg/zsh/cfg.d/export.zsh +++ /dev/null @@ -1,49 +0,0 @@ -# For Dotfiles -dotfls="${HOME}/dotfiles" -dotlib="${dotfls}/lib" -dotcfg="${dotfls}/cfg" -brewpr="$(/home/linuxbrew/.linuxbrew/bin/brew --prefix)" -gembin="$(ruby -e "puts Gem.user_dir")/bin" -BASHER_SHELL=zsh -BASHER_ROOT=/home/eeleater/.basher - -# Path -path=(${brewpr}/sbin ${brewpr}/bin) # Homebrew -path+=(/usr/local/sbin /usr/local/bin) # Local Bin -path+=(/usr/sbin /usr/bin) # /usr/bin -path+=(${dotfls}/bin) # Bin in Dotfiles -path+=(${dotlib}/basher/bin ${BASHER_ROOT}/cellar/bin) # Basher -path+=(${gembin}) # Ruby Gems -path+=(/usr/lib/jvm/default/bin) # Java -if pacman -Qm android-sdk-build-tools &>/dev/null; then - asdkver="$(pacman -Qm android-sdk-build-tools | awk '{print $2}' | cut -d'-' -f1 | cut -d'r' -f2)" - path+=(/opt/android-sdk/build-tools/${asdkver}); # Android SDK -fi - -path+=(/opt/phalcon-devtools) - -PTOOLSPATH="/opt/phalcon-devtools/" - -# Manpath -manpath+=(${brewpr}/share/man) - -# Infopath -infopath+=(${brewpr}/share/info) - -# XDG Data Dirs -XDG_DATA_DIRS+=(${brewpr}/share) - -# Editor Setting -EDITOR='nano' - -# Completions Paths -fpath+=(${dotlib}/completions/src) -fpath+=(${brewpr}/share/zsh/site-functions) -fpath+=(${dotlib}/local) -fpath+=(${BASHER_ROOT}/cellar/completions/zsh) - -# Actually export -export dotlib dotcfg brewpr gembin PATH MANPATH INFOPATH EDITOR XDG_DATA_DIRS PTOOLSPATH - -# Reload all Prompts -autoload -U promptinit && promptinit \ No newline at end of file diff --git a/cfg/zsh/cfg.d/ohmy.zsh b/cfg/zsh/cfg.d/ohmy.zsh deleted file mode 100644 index b0cb5d0..0000000 --- a/cfg/zsh/cfg.d/ohmy.zsh +++ /dev/null @@ -1,4 +0,0 @@ -export ZSH="${dotlib}/ohmyzsh" -DISABLE_AUTO_UPDATE="true" -ZSH_DISABLE_COMPFIX="true" -source ${ZSH}/oh-my-zsh.sh \ No newline at end of file diff --git a/cfg/zsh/cfg.d/source.d/00-highlighting.zsh b/cfg/zsh/cfg.d/source.d/00-highlighting.zsh deleted file mode 100644 index 7a17a76..0000000 --- a/cfg/zsh/cfg.d/source.d/00-highlighting.zsh +++ /dev/null @@ -1,173 +0,0 @@ -typeset -g ZERO=${(%):-%N} - -_zsh_highlight() -{ - local ret=$? - - if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCHMATCH_ACTIVE )); then - region_highlight=() - return $ret - fi - - setopt localoptions warncreateglobal noksharrays - local REPLY - local -a reply - - [[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret - - [[ $PENDING -gt 0 ]] && return $ret - - if [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified; then - -fast-highlight-init - -fast-highlight-process && region_highlight=( $reply ) || region_highlight=() - fi - - { - local cache_place - local -a region_highlight_copy - - if (( REGION_ACTIVE == 1 )); then - _zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR" - elif (( REGION_ACTIVE == 2 )); then - () { - local needle=$'\n' - integer min max - if (( MARK > CURSOR )) ; then - min=$CURSOR max=$MARK - else - min=$MARK max=$CURSOR - fi - (( min = ${${BUFFER[1,$min]}[(I)$needle]} )) - (( max += ${${BUFFER:($max-1)}[(i)$needle]} - 1 )) - _zsh_highlight_apply_zle_highlight region standout "$min" "$max" - } - fi - - (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END" - - (( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END" - - (( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END" - - return $ret - - } always { - typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER="$BUFFER" - typeset -g _ZSH_HIGHLIGHT_PRIOR_RACTIVE="$REGION_ACTIVE" - typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR - } -} - -_zsh_highlight_apply_zle_highlight() { - local entry="$1" default="$2" - integer first="$3" second="$4" - - local region="${zle_highlight[(r)${entry}:*]}" - - if [[ -z "$region" ]]; then - region=$default - else - region="${region#${entry}:}" - - if [[ -z "$region" ]] || [[ "$region" == none ]]; then - return - fi - fi - - integer start end - if (( first < second )); then - start=$first end=$second - else - start=$second end=$first - fi - region_highlight+=("$start $end $region") -} - - -_zsh_highlight_buffer_modified() -{ - [[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]] || [[ "$REGION_ACTIVE" != "$_ZSH_HIGHLIGHT_PRIOR_RACTIVE" ]] || { _zsh_highlight_cursor_moved && [[ "$REGION_ACTIVE" = 1 || "$REGION_ACTIVE" = 2 ]] } -} - -_zsh_highlight_cursor_moved() -{ - [[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR)) -} - -_zsh_highlight_call_widget() -{ - builtin zle "$@" && _zsh_highlight -} - -_zsh_highlight_bind_widgets() -{ - setopt localoptions noksharrays - typeset -F SECONDS - local prefix=orig-s$SECONDS-r$RANDOM - - zmodload zsh/zleparameter 2>/dev/null || { - print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' - return 1 - } - - local -U widgets_to_bind - widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank)}) - - widgets_to_bind+=(zle-line-finish) - - widgets_to_bind+=(zle-isearch-update) - - local cur_widget - for cur_widget in $widgets_to_bind; do - case $widgets[$cur_widget] in - - user:_zsh_highlight_widget_*);; - - user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:} - eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; - - completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]} - eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; - - builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; - - *) - if [[ $cur_widget == zle-* ]] && [[ -z $widgets[$cur_widget] ]]; then - _zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight } - zle -N $cur_widget _zsh_highlight_widget_$cur_widget - else - print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}" - fi - esac - done -} - -_zsh_highlight_bind_widgets || { - print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.' - return 1 -} - -_zsh_highlight_preexec_hook() -{ - typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER= - typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=0 -} - -autoload -U add-zsh-hook -add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || { - print -r -- >&2 'zsh-syntax-highlighting: failed loading add-zsh-hook.' -} - -ZSH_HIGHLIGHT_MAXLENGTH=10000 - -zmodload zsh/parameter 2>/dev/null - -autoload -U is-at-least -source "${dotlib}/highlight" - -[[ "${+termcap[Co]}" = 1 && "${termcap[Co]}" = "256" ]] && FAST_HIGHLIGHT_STYLES[variable]="fg=112" - --fast-highlight-fill-option-variables diff --git a/cfg/zsh/cfg.d/source.d/01-autosuggest.zsh b/cfg/zsh/cfg.d/source.d/01-autosuggest.zsh deleted file mode 100644 index 4126a91..0000000 --- a/cfg/zsh/cfg.d/source.d/01-autosuggest.zsh +++ /dev/null @@ -1,467 +0,0 @@ -autoload -Uz add-zsh-hook - -zmodload zsh/zpty - -ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8' -ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- -ZSH_AUTOSUGGEST_STRATEGY=default - -ZSH_AUTOSUGGEST_CLEAR_WIDGETS=( - history-search-forward - history-search-backward - history-beginning-search-forward - history-beginning-search-backward - history-substring-search-up - history-substring-search-down - up-line-or-history - down-line-or-history - accept-line -) - -ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=( - forward-char - end-of-line - vi-forward-char - vi-end-of-line - vi-add-eol -) - -ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=( -) - -ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( - forward-word - vi-forward-word - vi-forward-word-end - vi-forward-blank-word - vi-forward-blank-word-end -) - -ZSH_AUTOSUGGEST_IGNORE_WIDGETS=( - orig-\* - beep - run-help - set-local-history - which-command - yank -) - -ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE= -ZSH_AUTOSUGGEST_ASYNC_PTY_NAME=zsh_autosuggest_pty - -_zsh_autosuggest_escape_command() { - setopt localoptions EXTENDED_GLOB - echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" -} - -_zsh_autosuggest_feature_detect_zpty_returns_fd() { - typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD - typeset -h REPLY - - zpty zsh_autosuggest_feature_detect '{ zshexit() { kill -KILL $$; sleep 1 } }' - - if (( REPLY )); then - _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=1 - else - _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=0 - fi - - zpty -d zsh_autosuggest_feature_detect -} - -_zsh_autosuggest_incr_bind_count() { - if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then - ((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]++)) - else - _ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=1 - fi - - bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1] -} - -_zsh_autosuggest_get_bind_count() { - if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then - bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1] - else - bind_count=0 - fi -} - -_zsh_autosuggest_bind_widget() { - typeset -gA _ZSH_AUTOSUGGEST_BIND_COUNTS - - local widget=$1 - local autosuggest_action=$2 - local prefix=$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX - - local -i bind_count - - case $widgets[$widget] in - # Already bound - user:_zsh_autosuggest_(bound|orig)_*);; - - user:*) - _zsh_autosuggest_incr_bind_count $widget - zle -N $prefix${bind_count}-$widget ${widgets[$widget]#*:} - ;; - - builtin) - _zsh_autosuggest_incr_bind_count $widget - eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }" - zle -N $prefix${bind_count}-$widget _zsh_autosuggest_orig_$widget - ;; - - completion:*) - _zsh_autosuggest_incr_bind_count $widget - eval "zle -C $prefix${bind_count}-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}" - ;; - esac - - _zsh_autosuggest_get_bind_count $widget - - eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() { - _zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@ - }" - - zle -N $widget _zsh_autosuggest_bound_${bind_count}_$widget -} - -_zsh_autosuggest_bind_widgets() { - local widget - local ignore_widgets - - ignore_widgets=( - .\* - _\* - zle-\* - autosuggest-\* - $ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\* - $ZSH_AUTOSUGGEST_IGNORE_WIDGETS - ) - - for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do - if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then - _zsh_autosuggest_bind_widget $widget clear - elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then - _zsh_autosuggest_bind_widget $widget accept - elif [ ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]; then - _zsh_autosuggest_bind_widget $widget execute - elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then - _zsh_autosuggest_bind_widget $widget partial_accept - else - _zsh_autosuggest_bind_widget $widget modify - fi - done -} - -_zsh_autosuggest_invoke_original_widget() { - [ $# -gt 0 ] || return - - local original_widget_name="$1" - - shift - - if [ $widgets[$original_widget_name] ]; then - zle $original_widget_name -- $@ - fi -} - -_zsh_autosuggest_highlight_reset() { - typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT - - if [ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]; then - region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}") - unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT - fi -} - -_zsh_autosuggest_highlight_apply() { - typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT - - if [ $#POSTDISPLAY -gt 0 ]; then - _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE" - region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT") - else - unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT - fi -} - -_zsh_autosuggest_disable() { - typeset -g _ZSH_AUTOSUGGEST_DISABLED - _zsh_autosuggest_clear -} - -_zsh_autosuggest_enable() { - unset _ZSH_AUTOSUGGEST_DISABLED - - if [ $#BUFFER -gt 0 ]; then - _zsh_autosuggest_fetch - fi -} - -_zsh_autosuggest_toggle() { - if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then - _zsh_autosuggest_enable - else - _zsh_autosuggest_disable - fi -} - -_zsh_autosuggest_clear() { - unset POSTDISPLAY - - _zsh_autosuggest_invoke_original_widget $@ -} - -_zsh_autosuggest_modify() { - local -i retval - - local -i KEYS_QUEUED_COUNT - - local orig_buffer="$BUFFER" - local orig_postdisplay="$POSTDISPLAY" - - unset POSTDISPLAY - - _zsh_autosuggest_invoke_original_widget $@ - retval=$? - - if [[ $PENDING > 0 ]] || [[ $KEYS_QUEUED_COUNT > 0 ]]; then - return $retval - fi - - if [ $#BUFFER -gt $#orig_buffer ]; then - local added=${BUFFER#$orig_buffer} - - if [ "$added" = "${orig_postdisplay:0:$#added}" ]; then - POSTDISPLAY="${orig_postdisplay:$#added}" - return $retval - fi - fi - - if [ "$BUFFER" = "$orig_buffer" ]; then - POSTDISPLAY="$orig_postdisplay" - return $retval - fi - - if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then - return $? - fi - - if [ $#BUFFER -gt 0 ]; then - if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -le "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then - _zsh_autosuggest_fetch - fi - fi - - return $retval -} - -_zsh_autosuggest_fetch() { - if zpty -t "$ZSH_AUTOSUGGEST_ASYNC_PTY_NAME" &>/dev/null; then - _zsh_autosuggest_async_request "$BUFFER" - else - local suggestion - _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY "$BUFFER" - _zsh_autosuggest_suggest "$suggestion" - fi -} - -_zsh_autosuggest_suggest() { - local suggestion="$1" - - if [ -n "$suggestion" ] && [ $#BUFFER -gt 0 ]; then - POSTDISPLAY="${suggestion#$BUFFER}" - else - unset POSTDISPLAY - fi -} - -_zsh_autosuggest_accept() { - local -i max_cursor_pos=$#BUFFER - - if [ "$KEYMAP" = "vicmd" ]; then - max_cursor_pos=$((max_cursor_pos - 1)) - fi - - if [ $CURSOR -eq $max_cursor_pos ]; then - BUFFER="$BUFFER$POSTDISPLAY" - unset POSTDISPLAY - CURSOR=${#BUFFER} - fi - - _zsh_autosuggest_invoke_original_widget $@ -} - -_zsh_autosuggest_execute() { - BUFFER="$BUFFER$POSTDISPLAY" - unset POSTDISPLAY - _zsh_autosuggest_invoke_original_widget "accept-line" -} - -_zsh_autosuggest_partial_accept() { - local -i retval - local original_buffer="$BUFFER" - BUFFER="$BUFFER$POSTDISPLAY" - _zsh_autosuggest_invoke_original_widget $@ - retval=$? - - if [ $CURSOR -gt $#original_buffer ]; then - POSTDISPLAY="$RBUFFER" - BUFFER="$LBUFFER" - else - BUFFER="$original_buffer" - fi - - return $retval -} - -for action in clear modify fetch suggest accept partial_accept execute enable disable toggle; do - eval "_zsh_autosuggest_widget_$action() { - local -i retval - - _zsh_autosuggest_highlight_reset - - _zsh_autosuggest_$action \$@ - retval=\$? - - _zsh_autosuggest_highlight_apply - - zle -R - - return \$retval - }" -done - -zle -N autosuggest-fetch _zsh_autosuggest_widget_fetch -zle -N autosuggest-suggest _zsh_autosuggest_widget_suggest -zle -N autosuggest-accept _zsh_autosuggest_widget_accept -zle -N autosuggest-clear _zsh_autosuggest_widget_clear -zle -N autosuggest-execute _zsh_autosuggest_widget_execute -zle -N autosuggest-enable _zsh_autosuggest_widget_enable -zle -N autosuggest-disable _zsh_autosuggest_widget_disable -zle -N autosuggest-toggle _zsh_autosuggest_widget_toggle - -_zsh_autosuggest_strategy_default() { - emulate -L zsh - setopt EXTENDED_GLOB - local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}" - suggestion="${history[(r)$prefix*]}" -} - -_zsh_autosuggest_strategy_match_prev_cmd() { - local prefix="${1//(#m)[\\()\[\]|*?~]/\\$MATCH}" - local history_match_keys - history_match_keys=(${(k)history[(R)$prefix*]}) - local histkey="${history_match_keys[1]}" - local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")" - - for key in "${(@)history_match_keys[1,200]}"; do - [[ $key -gt 1 ]] || break - - if [[ "${history[$((key - 1))]}" == "$prev_cmd" ]]; then - histkey="$key" - break - fi - done - - suggestion="$history[$histkey]" -} - -_zsh_autosuggest_async_server() { - emulate -R zsh - - zshexit() { - kill -KILL $$ - sleep 1 - } - - stty -onlcr - - exec 2>/dev/null - - local strategy=$1 - local last_pid - - while IFS='' read -r -d $'\0' query; do - kill -KILL $last_pid &>/dev/null - - ( - local suggestion - _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY "$query" - echo -n -E "$suggestion"$'\0' - ) & - - last_pid=$! - done -} - -_zsh_autosuggest_async_request() { - zpty -w -n $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "${1}"$'\0' -} - -_zsh_autosuggest_async_response() { - setopt LOCAL_OPTIONS EXTENDED_GLOB - - local suggestion - - zpty -rt $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME suggestion '*'$'\0' 2>/dev/null - zle autosuggest-suggest -- "${suggestion%%$'\0'##}" -} - -_zsh_autosuggest_async_pty_create() { - typeset -h REPLY - - if [ $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD -eq 0 ]; then - integer -l zptyfd - exec {zptyfd}>&1 - exec {zptyfd}>&- - fi - - zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "_zsh_autosuggest_async_server _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY" - - if (( REPLY )); then - _ZSH_AUTOSUGGEST_PTY_FD=$REPLY - else - _ZSH_AUTOSUGGEST_PTY_FD=$zptyfd - fi - - zle -F $_ZSH_AUTOSUGGEST_PTY_FD _zsh_autosuggest_async_response -} - -_zsh_autosuggest_async_pty_destroy() { - if zpty -t $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null; then - zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null - - zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null - fi -} - -_zsh_autosuggest_async_pty_recreate() { - _zsh_autosuggest_async_pty_destroy - _zsh_autosuggest_async_pty_create -} - -_zsh_autosuggest_async_start() { - typeset -g _ZSH_AUTOSUGGEST_PTY_FD - - _zsh_autosuggest_feature_detect_zpty_returns_fd - _zsh_autosuggest_async_pty_recreate - - add-zsh-hook precmd _zsh_autosuggest_async_pty_recreate -} - -_zsh_autosuggest_start() { - add-zsh-hook -d precmd _zsh_autosuggest_start - - _zsh_autosuggest_bind_widgets - - add-zsh-hook precmd _zsh_autosuggest_bind_widgets - - if [ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]; then - _zsh_autosuggest_async_start - fi -} - -add-zsh-hook precmd _zsh_autosuggest_start - diff --git a/cfg/zsh/cfg.d/source.d/alias-brew.zsh b/cfg/zsh/cfg.d/source.d/alias-brew.zsh deleted file mode 100644 index bbababf..0000000 --- a/cfg/zsh/cfg.d/source.d/alias-brew.zsh +++ /dev/null @@ -1,4 +0,0 @@ -alias brews='brew list -1' -alias bubo='brew update && brew outdated' -alias bubc='brew upgrade && brew cleanup' -alias bubu='bubo && bubc' \ No newline at end of file diff --git a/cfg/zsh/cfg.d/source.d/alias-os.zsh b/cfg/zsh/cfg.d/source.d/alias-os.zsh deleted file mode 100644 index e0101c7..0000000 --- a/cfg/zsh/cfg.d/source.d/alias-os.zsh +++ /dev/null @@ -1,219 +0,0 @@ -if (( $+commands[trizen] )); then - alias trconf='trizen -C' - alias trupg='trizen -Syua' - alias trsu='trizen -Syua --noconfirm' - alias trin='trizen -S' - alias trins='trizen -U' - alias trre='trizen -R' - alias trrem='trizen -Rns' - alias trrep='trizen -Si' - alias trreps='trizen -Ss' - alias trloc='trizen -Qi' - alias trlocs='trizen -Qs' - alias trlst='trizen -Qe' - alias trorph='trizen -Qtd' - alias trinsd='trizen -S --asdeps' - alias trmir='trizen -Syy' - - - if (( $+commands[abs] && $+commands[aur] )); then - alias trupd='trizen -Sy && sudo abs && sudo aur' - elif (( $+commands[abs] )); then - alias trupd='trizen -Sy && sudo abs' - elif (( $+commands[aur] )); then - alias trupd='trizen -Sy && sudo aur' - else - alias trupd='trizen -Sy' - fi -fi - -if (( $+commands[yaourt] )); then - alias yaconf='yaourt -C' - alias yaupg='yaourt -Syua' - alias yasu='yaourt -Syua --noconfirm' - alias yain='yaourt -S' - alias yains='yaourt -U' - alias yare='yaourt -R' - alias yarem='yaourt -Rns' - alias yarep='yaourt -Si' - alias yareps='yaourt -Ss' - alias yaloc='yaourt -Qi' - alias yalocs='yaourt -Qs' - alias yalst='yaourt -Qe' - alias yaorph='yaourt -Qtd' - alias yainsd='yaourt -S --asdeps' - alias yamir='yaourt -Syy' - - - if (( $+commands[abs] && $+commands[aur] )); then - alias yaupd='yaourt -Sy && sudo abs && sudo aur' - elif (( $+commands[abs] )); then - alias yaupd='yaourt -Sy && sudo abs' - elif (( $+commands[aur] )); then - alias yaupd='yaourt -Sy && sudo aur' - else - alias yaupd='yaourt -Sy' - fi -fi - -if (( $+commands[yay] )); then - alias yaconf='yay -Pg' - alias yaupg='yay -Syu' - alias yasu='yay -Syu --noconfirm' - alias yain='yay -S' - alias yains='yay -U' - alias yare='yay -R' - alias yarem='yay -Rns' - alias yarep='yay -Si' - alias yareps='yay -Ss' - alias yaloc='yay -Qi' - alias yalocs='yay -Qs' - alias yalst='yay -Qe' - alias yaorph='yay -Qtd' - alias yainsd='yay -S --asdeps' - alias yamir='yay -Syy' - - - if (( $+commands[abs] && $+commands[aur] )); then - alias yaupd='yay -Sy && sudo abs && sudo aur' - elif (( $+commands[abs] )); then - alias yaupd='yay -Sy && sudo abs' - elif (( $+commands[aur] )); then - alias yaupd='yay -Sy && sudo aur' - else - alias yaupd='yay -Sy' - fi -fi - -if (( $+commands[pacaur] )); then - alias paupg='pacaur -Syu' - alias pasu='pacaur -Syu --noconfirm' - alias pain='pacaur -S' - alias pains='pacaur -U' - alias pare='pacaur -R' - alias parem='pacaur -Rns' - alias parep='pacaur -Si' - alias pareps='pacaur -Ss' - alias paloc='pacaur -Qi' - alias palocs='pacaur -Qs' - alias palst='pacaur -Qe' - alias paorph='pacaur -Qtd' - alias painsd='pacaur -S --asdeps' - alias pamir='pacaur -Syy' - - if (( $+commands[abs] && $+commands[aur] )); then - alias paupd='pacaur -Sy && sudo abs && sudo aur' - elif (( $+commands[abs] )); then - alias paupd='pacaur -Sy && sudo abs' - elif (( $+commands[aur] )); then - alias paupd='pacaur -Sy && sudo aur' - else - alias paupd='pacaur -Sy' - fi -fi - -if (( $+commands[trizen] )); then - function upgrade() { - trizen -Syu - } -elif (( $+commands[pacaur] )); then - function upgrade() { - pacaur -Syu - } -elif (( $+commands[yaourt] )); then - function upgrade() { - yaourt -Syu - } -elif (( $+commands[yay] )); then - function upgrade() { - yay -Syu - } -else - function upgrade() { - sudo pacman -Syu - } -fi - -# Pacman - https://wiki.archlinux.org/index.php/Pacman_Tips -alias pacupg='sudo pacman -Syu' -alias pacin='sudo pacman -S' -alias pacins='sudo pacman -U' -alias pacre='sudo pacman -R' -alias pacrem='sudo pacman -Rns' -alias pacrep='pacman -Si' -alias pacreps='pacman -Ss' -alias pacloc='pacman -Qi' -alias paclocs='pacman -Qs' -alias pacinsd='sudo pacman -S --asdeps' -alias pacmir='sudo pacman -Syy' -alias paclsorphans='sudo pacman -Qdt' -alias pacrmorphans='sudo pacman -Rs $(pacman -Qtdq)' -alias pacfileupg='sudo pacman -Fy' -alias pacfiles='pacman -Fs' -alias pacls='pacman -Ql' -alias pacown='pacman -Qo' - - -if (( $+commands[abs] && $+commands[aur] )); then - alias pacupd='sudo pacman -Sy && sudo abs && sudo aur' -elif (( $+commands[abs] )); then - alias pacupd='sudo pacman -Sy && sudo abs' -elif (( $+commands[aur] )); then - alias pacupd='sudo pacman -Sy && sudo aur' -else - alias pacupd='sudo pacman -Sy' -fi - -function paclist() { - # Source: https://bbs.archlinux.org/viewtopic.php?id=93683 - LC_ALL=C pacman -Qei $(pacman -Qu | cut -d " " -f 1) | \ - awk 'BEGIN {FS=":"} /^Name/{printf("\033[1;36m%s\033[1;37m", $2)} /^Description/{print $2}' -} - -function pacdisowned() { - emulate -L zsh - - tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$ - db=$tmp/db - fs=$tmp/fs - - mkdir "$tmp" - trap 'rm -rf "$tmp"' EXIT - - pacman -Qlq | sort -u > "$db" - - find /bin /etc /lib /sbin /usr ! -name lost+found \ - \( -type d -printf '%p/\n' -o -print \) | sort > "$fs" - - comm -23 "$fs" "$db" -} - -function pacmanallkeys() { - emulate -L zsh - curl -s https://www.archlinux.org/people/{developers,trustedusers}/ | \ - awk -F\" '(/pgp.mit.edu/) { sub(/.*search=0x/,""); print $1}' | \ - xargs sudo pacman-key --recv-keys -} - -function pacmansignkeys() { - emulate -L zsh - for key in $*; do - sudo pacman-key --recv-keys $key - sudo pacman-key --lsign-key $key - printf 'trust\n3\n' | sudo gpg --homedir /etc/pacman.d/gnupg \ - --no-permission-warning --command-fd 0 --edit-key $key - done -} - -if (( $+commands[xdg-open] )); then - function pacweb() { - pkg="$1" - infos="$(pacman -Si "$pkg")" - if [[ -z "$infos" ]]; then - return - fi - repo="$(grep '^Repo' <<< "$infos" | grep -oP '[^ ]+$')" - arch="$(grep '^Arch' <<< "$infos" | grep -oP '[^ ]+$')" - xdg-open "https://www.archlinux.org/packages/$repo/$arch/$pkg/" &>/dev/null - } -fi diff --git a/cfg/zsh/cfg.d/source.d/alias-systemd.zsh b/cfg/zsh/cfg.d/source.d/alias-systemd.zsh deleted file mode 100644 index 27d7e62..0000000 --- a/cfg/zsh/cfg.d/source.d/alias-systemd.zsh +++ /dev/null @@ -1,8 +0,0 @@ -cmds=(status show start stop reload restart enable disable daemon-reload) - -for cmd in $cmds; do - alias sc-$cmd="sudo systemctl $cmd" -done - -alias sc-enablenow="sc-enable --now" -alias sc-disablenow="sc-disable --now" \ No newline at end of file diff --git a/cfg/zsh/cfg.d/source.d/function-cnf.zsh b/cfg/zsh/cfg.d/source.d/function-cnf.zsh deleted file mode 100644 index 291ed00..0000000 --- a/cfg/zsh/cfg.d/source.d/function-cnf.zsh +++ /dev/null @@ -1 +0,0 @@ -[[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh diff --git a/cfg/zsh/cfg.d/source.d/function-dircolors.zsh b/cfg/zsh/cfg.d/source.d/function-dircolors.zsh deleted file mode 100644 index 8f631c0..0000000 --- a/cfg/zsh/cfg.d/source.d/function-dircolors.zsh +++ /dev/null @@ -1 +0,0 @@ -eval `dircolors ${dotcfg}/dir/cfg` diff --git a/cfg/zsh/cfg.d/source.d/function-extract.zsh b/cfg/zsh/cfg.d/source.d/function-extract.zsh deleted file mode 100644 index 87d2023..0000000 --- a/cfg/zsh/cfg.d/source.d/function-extract.zsh +++ /dev/null @@ -1,72 +0,0 @@ -alias x=extract - -extract() { - local remove_archive - local success - local extract_dir - - if (( $# == 0 )); then - cat <<-'EOF' >&2 - Usage: extract [-option] [file ...] - - Options: - -r, --remove Remove archive. - EOF - fi - - remove_archive=1 - if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then - remove_archive=0 - shift - fi - - while (( $# > 0 )); do - if [[ ! -f "$1" ]]; then - echo "extract: '$1' is not a valid file" >&2 - shift - continue - fi - - success=0 - extract_dir="${1:t:r}" - case "$1" in - (*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$1" | tar xv } || tar zxvf "$1" ;; - (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;; - (*.tar.xz|*.txz) - tar --xz --help &> /dev/null \ - && tar --xz -xvf "$1" \ - || xzcat "$1" | tar xvf - ;; - (*.tar.zma|*.tlz) - tar --lzma --help &> /dev/null \ - && tar --lzma -xvf "$1" \ - || lzcat "$1" | tar xvf - ;; - (*.tar) tar xvf "$1" ;; - (*.gz) (( $+commands[pigz] )) && pigz -d "$1" || gunzip "$1" ;; - (*.bz2) bunzip2 "$1" ;; - (*.xz) unxz "$1" ;; - (*.lzma) unlzma "$1" ;; - (*.Z) uncompress "$1" ;; - (*.zip|*.war|*.jar|*.sublime-package|*.ipsw|*.xpi|*.apk) unzip "$1" -d $extract_dir ;; - (*.rar) unrar x -ad "$1" ;; - (*.7z) 7za x "$1" ;; - (*.deb) - mkdir -p "$extract_dir/control" - mkdir -p "$extract_dir/data" - cd "$extract_dir"; ar vx "../${1}" > /dev/null - cd control; tar xzvf ../control.tar.gz - cd ../data; extract ../data.tar.* - cd ..; rm *.tar.* debian-binary - cd .. - ;; - (*) - echo "extract: '$1' cannot be extracted" >&2 - success=1 - ;; - esac - - (( success = $success > 0 ? $success : $? )) - (( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1" - shift - done -} - diff --git a/cfg/zsh/cfg.d/source.d/function-fzf.zsh b/cfg/zsh/cfg.d/source.d/function-fzf.zsh deleted file mode 100644 index 3ef1dcc..0000000 --- a/cfg/zsh/cfg.d/source.d/function-fzf.zsh +++ /dev/null @@ -1,4 +0,0 @@ -[[ $- == *i* && -f "/usr/share/fzf/completion.zsh" ]] && source "/usr/share/fzf/completion.zsh" 2> /dev/null -[[ -f "/usr/share/fzf/key-bindings.zsh" ]] && source "/usr/share/fzf/key-bindings.zsh" -[[ $- == *i* && -f "/home/linuxbrew/.linuxbrew/opt/fzf/shell/completion.zsh" ]] && source "/home/linuxbrew/.linuxbrew/opt/fzf/shell/completion.zsh" 2> /dev/null -[[ -f "/home/linuxbrew/.linuxbrew/opt/fzf/shell/key-bindings.zsh" ]] && source "/home/linuxbrew/.linuxbrew/opt/fzf/shell/key-bindings.zsh" \ No newline at end of file diff --git a/cfg/zsh/cfg.d/source.d/function-gitignore.zsh b/cfg/zsh/cfg.d/source.d/function-gitignore.zsh deleted file mode 100644 index 1c1e8fd..0000000 --- a/cfg/zsh/cfg.d/source.d/function-gitignore.zsh +++ /dev/null @@ -1,53 +0,0 @@ -ZSH_PLUGIN_GITIGNORE_PATH=$(dirname $0) -ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS=${dotlib}/gitignore - -function gie () { ${EDITOR} .gitignore } - -function gi() { - if [[ $# -eq 0 ]]; then - cat .gitignore - return 0 - fi - - for t in $*; do - get_gitignore_template $t - done -} - -function gii() { - if [[ $# -eq 0 ]]; then - cat .gitignore - return 0 - fi - - gi $* >>! .gitignore -} - -function get_gitignore_template() { - for tpath in ${(@s/:/)ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS}; do; - local file=$(find $tpath -iname "$1.gitignore") - if [[ ! -z $file ]]; then - comment=$(basename $file | sed -e 's/.gitignore$//') - echo - echo "### $comment" - cat $file - break; - fi - done; -} - -_gitignore_get_template_list() { - (for tpath in ${(@s/:/)ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS}; do; find $tpath -type f -name "*.gitignore"; done) \ - | xargs -n 1 basename \ - | sed -e 's/.gitignore$//' -e 's/\(.*\)/\L\1/' \ - | sort -u -} - -_gitignore () { - compset -P '*,' - compadd -S '' `_gitignore_get_template_list` -} - -compdef _gitignore gi -compdef _gitignore gii - diff --git a/cfg/zsh/cfg.d/source.d/function-tmux.zsh b/cfg/zsh/cfg.d/source.d/function-tmux.zsh deleted file mode 100644 index 1a1c55e..0000000 --- a/cfg/zsh/cfg.d/source.d/function-tmux.zsh +++ /dev/null @@ -1,63 +0,0 @@ -alias ta='tmux attach -t' -alias tad='tmux attach -d -t' -alias ts='tmux new-session -s' -alias tl='tmux list-sessions' -alias tksv='tmux kill-server' -alias tkss='tmux kill-session -t' - -if which tmux &> /dev/null -then - [[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false - [[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true - [[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true - [[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART - [[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true - [[ -n "$ZSH_TMUX_ITERM2" ]] || ZSH_TMUX_ITERM2=false - [[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen" - [[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color" - - local zsh_tmux_plugin_path=${dotcfg}/tmux - - if [[ `tput colors` == "256" ]] - then - export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR - else - export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR - fi - - if [[ "$ZSH_TMUX_ITERM2" == "false" ]] && [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]] - then - _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.extra.conf" - else - _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.only.conf" - fi - - function _zsh_tmux_plugin_run() - { - if [[ -n "$@" ]] - then - \tmux $@ - elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] - then - \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` attach || \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` new-session - [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit - else - \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` - [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit - fi - } - - compdef _tmux _zsh_tmux_plugin_run - alias tmux=_zsh_tmux_plugin_run - if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]] - then - if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]] - then - export ZSH_TMUX_AUTOSTARTED=true - _zsh_tmux_plugin_run - fi - fi -else - print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." -fi - diff --git a/cfg/zsh/cfg.d/source.d/function-workfix.zsh b/cfg/zsh/cfg.d/source.d/function-workfix.zsh deleted file mode 100644 index 004dde4..0000000 --- a/cfg/zsh/cfg.d/source.d/function-workfix.zsh +++ /dev/null @@ -1,3 +0,0 @@ -# Fix MobaXterm Home/End key with ZSH -bindkey '^[[H' beginning-of-line -bindkey '^[[F' end-of-line \ No newline at end of file diff --git a/cfg/zsh/cfg.d/source.zsh b/cfg/zsh/cfg.d/source.zsh deleted file mode 100644 index 50d00dd..0000000 --- a/cfg/zsh/cfg.d/source.zsh +++ /dev/null @@ -1,10 +0,0 @@ -alias rm='rm -i' -alias cp='cp -i' -alias mv='mv -i' -alias la='ls -lAh' - -for file in ${dotcfg}/zsh/cfg.d/source.d/*.zsh; do - source $file -done - -source /usr/share/lmod/lmod/init/zsh \ No newline at end of file diff --git a/cfg/zsh/cfg.zsh b/cfg/zsh/cfg.zsh deleted file mode 100644 index eda0a02..0000000 --- a/cfg/zsh/cfg.zsh +++ /dev/null @@ -1,7 +0,0 @@ -# Source all files -for file in ${HOME}/dotfiles/cfg/zsh/cfg.d/*.zsh; do - source $file -done - -# Prompt -prompt z4rr3t \ No newline at end of file diff --git a/install b/install deleted file mode 100755 index 35ad0a3..0000000 --- a/install +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -cd ${HOME}/dotfiles - -echo "Installing Dotfiles - Please Wait!" -git submodule update --init --recursive -lib/dotbot/bin/dotbot -d . -c cfg/dotbot/cfg ${@} diff --git a/lib/basher b/lib/basher deleted file mode 160000 index dcf5c0d..0000000 --- a/lib/basher +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dcf5c0dd9e033712fdac3da2bfdfeb430f13d16a diff --git a/lib/completions b/lib/completions deleted file mode 160000 index b512d57..0000000 --- a/lib/completions +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b512d57b6d0d2b85368a8068ec1a13288a93d267 diff --git a/lib/dotbot b/lib/dotbot deleted file mode 160000 index d20984f..0000000 --- a/lib/dotbot +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d20984f5acbb439347399ced4bd242e4ab9ccb07 diff --git a/lib/gitignore b/lib/gitignore deleted file mode 160000 index 499ae89..0000000 --- a/lib/gitignore +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 499ae899e7b54e701e878759f73d9092302fd07a diff --git a/lib/has b/lib/has deleted file mode 160000 index bdf7c2f..0000000 --- a/lib/has +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bdf7c2ffe6f6dd3a2dcfb9ef7d4794b5ffc4402b diff --git a/lib/highlight b/lib/highlight deleted file mode 100644 index 3f03272..0000000 --- a/lib/highlight +++ /dev/null @@ -1,715 +0,0 @@ -# ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors -# Copyright (c) 2016-2017 Sebastian Gniazdowski (modifications) -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, are permitted -# provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this list of conditions -# and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, this list of -# conditions and the following disclaimer in the documentation and/or other materials provided -# with the distribution. -# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors -# may be used to endorse or promote products derived from this software without specific prior -# written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ------------------------------------------------------------------------------------------------- - -typeset -gA __fast_highlight_main__command_type_cache - -# Define default styles. You can set this after loading the plugin in -# Zshrc and use 256 via numbers, like: fg=150 -typeset -gA FAST_HIGHLIGHT_STYLES -: ${FAST_HIGHLIGHT_STYLES[default]:=none} -: ${FAST_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold} -: ${FAST_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow} -: ${FAST_HIGHLIGHT_STYLES[alias]:=fg=green} -: ${FAST_HIGHLIGHT_STYLES[suffix-alias]:=fg=green} -: ${FAST_HIGHLIGHT_STYLES[builtin]:=fg=green} -: ${FAST_HIGHLIGHT_STYLES[function]:=fg=green} -: ${FAST_HIGHLIGHT_STYLES[command]:=fg=green} -: ${FAST_HIGHLIGHT_STYLES[precommand]:=fg=green} -: ${FAST_HIGHLIGHT_STYLES[commandseparator]:=none} -: ${FAST_HIGHLIGHT_STYLES[hashed-command]:=fg=green} -: ${FAST_HIGHLIGHT_STYLES[path]:=fg=magenta} -: ${FAST_HIGHLIGHT_STYLES[path_pathseparator]:=} -: ${FAST_HIGHLIGHT_STYLES[globbing]:=fg=blue,bold} -: ${FAST_HIGHLIGHT_STYLES[history-expansion]:=fg=blue,bold} -: ${FAST_HIGHLIGHT_STYLES[single-hyphen-option]:=fg=cyan} -: ${FAST_HIGHLIGHT_STYLES[double-hyphen-option]:=fg=cyan} -: ${FAST_HIGHLIGHT_STYLES[back-quoted-argument]:=none} -: ${FAST_HIGHLIGHT_STYLES[single-quoted-argument]:=fg=yellow} -: ${FAST_HIGHLIGHT_STYLES[double-quoted-argument]:=fg=yellow} -: ${FAST_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow} -: ${FAST_HIGHLIGHT_STYLES[back-or-dollar-double-quoted-argument]:=fg=cyan} -: ${FAST_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan} -: ${FAST_HIGHLIGHT_STYLES[assign]:=none} -: ${FAST_HIGHLIGHT_STYLES[redirection]:=none} -: ${FAST_HIGHLIGHT_STYLES[comment]:=fg=black,bold} -: ${FAST_HIGHLIGHT_STYLES[variable]:=none} - - -typeset -gA __FAST_HIGHLIGHT_TOKEN_TYPES - -__FAST_HIGHLIGHT_TOKEN_TYPES=( - - # Precommand - - 'builtin' 1 - 'command' 1 - 'exec' 1 - 'nocorrect' 1 - 'noglob' 1 - 'pkexec' 1 # immune to #121 because it's usually not passed --option flags - - # Control flow - # Tokens that, at (naively-determined) "command position", are followed by - # a de jure command position. All of these are reserved words. - - $'\x7b' 2 # block - $'\x28' 2 # subshell - '()' 2 # anonymous function - 'while' 2 - 'until' 2 - 'if' 2 - 'then' 2 - 'elif' 2 - 'else' 2 - 'do' 2 - 'time' 2 - 'coproc' 2 - '!' 2 # reserved word; unrelated to $histchars[1] - - # Command separators - - '|' 3 - '||' 3 - ';' 3 - '&' 3 - '&&' 3 - '|&' 3 - '&!' 3 - '&|' 3 - # ### 'case' syntax, but followed by a pattern, not by a command - # ';;' ';&' ';|' -) - -# A hash instead of multiple globals -typeset -gA FAST_HIGHLIGHT - -# Get the type of a command. -# -# Uses the zsh/parameter module if available to avoid forks, and a -# wrapper around 'type -w' as fallback. -# -# Takes a single argument. -# -# The result will be stored in REPLY. --fast-highlight-main-type() { - REPLY=$__fast_highlight_main__command_type_cache[(e)$1] - [[ -z "$REPLY" ]] && { - - if zmodload -e zsh/parameter; then - if (( $+aliases[(e)$1] )); then - REPLY=alias - elif (( $+functions[(e)$1] )); then - REPLY=function - elif (( $+builtins[(e)$1] )); then - REPLY=builtin - elif (( $+commands[(e)$1] )); then - REPLY=command - elif (( $+saliases[(e)${1##*.}] )); then - REPLY='suffix alias' - elif (( $reswords[(Ie)$1] )); then - REPLY=reserved - # zsh 5.2 and older have a bug whereby running 'type -w ./sudo' implicitly - # runs 'hash ./sudo=/usr/local/bin/./sudo' (assuming /usr/local/bin/sudo - # exists and is in $PATH). Avoid triggering the bug, at the expense of - # falling through to the $() below, incurring a fork. (Issue #354.) - # - # The second disjunct mimics the isrelative() C call from the zsh bug. - elif [[ $1 != */* || "${+ZSH_ARGZERO}" = "1" ]] && ! builtin type -w -- $1 >/dev/null 2>&1; then - REPLY=none - fi - fi - - [[ -z "$REPLY" ]] && REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }" - - [[ "$REPLY" = "none" ]] && { - [[ -d "$1" ]] && REPLY="dirpath" || { - for cdpath_dir in $cdpath; do - [[ -d "$cdpath_dir/$1" ]] && { REPLY="dirpath"; break; } - done - } - } - - __fast_highlight_main__command_type_cache[(e)$1]=$REPLY - - } -} - -# Below are variables that must be defined in outer -# scope so that they are reachable in *-process() --fast-highlight-fill-option-variables() { - if [[ -o ignore_braces ]] || eval '[[ -o ignore_close_braces ]] 2>/dev/null'; then - FAST_HIGHLIGHT[right_brace_is_recognised_everywhere]=0 - else - FAST_HIGHLIGHT[right_brace_is_recognised_everywhere]=1 - fi - - if [[ -o path_dirs ]]; then - FAST_HIGHLIGHT[path_dirs_was_set]=1 - else - FAST_HIGHLIGHT[path_dirs_was_set]=0 - fi - - if [[ -o multi_func_def ]]; then - FAST_HIGHLIGHT[multi_func_def]=1 - else - FAST_HIGHLIGHT[multi_func_def]=0 - fi - - if [[ -o interactive_comments ]]; then - FAST_HIGHLIGHT[ointeractive_comments]=1 - else - FAST_HIGHLIGHT[ointeractive_comments]=0 - fi -} - -# Main syntax highlighting function. --fast-highlight-process() -{ - emulate -L zsh - setopt extendedglob bareglobqual nonomatch noksharrays - - [[ $CONTEXT == "select" ]] && return 0 - - (( FAST_HIGHLIGHT[path_dirs_was_set] )) && setopt PATH_DIRS - (( FAST_HIGHLIGHT[ointeractive_comments] )) && local interactive_comments= # _set_ to empty - - # Variable declarations and initializations - # in_array_assignment true between 'a=(' and the matching ')' - # braces_stack: "R" for round, "Q" for square, "Y" for curly - # mybuf, cdpath_dir are used in sub-functions - local start_pos=0 end_pos start end highlight_glob=1 arg style in_array_assignment=0 MATCH expanded_path braces_stack buf="$PREBUFFER$BUFFER" mybuf cdpath_dir cur_cmd alias_target - # arg_type can be 0, 1, 2 or 3, i.e. precommand, control flow, command separator - # idx and end_idx are used in sub-functions - # for this_word and next_word look below at commented integers and at state machine description - integer arg_type=0 MBEGIN MEND in_redirection len=${#buf} already_added offset idx end_idx this_word=1 next_word=0 insane_alias pos - local -a match mbegin mend - - # integer BIT_start=1 BIT_regular=2 BIT_sudo_opt=4 BIT_sudo_arg=8 BIT_always=16 - - # State machine - # - # The states are: - # - :start: Command word - # - :sudo_opt: A leading-dash option to sudo (such as "-u" or "-i") - # - :sudo_arg: The argument to a sudo leading-dash option that takes one, - # when given as a separate word; i.e., "foo" in "-u foo" (two - # words) but not in "-ufoo" (one word). - # - :regular: "Not a command word", and command delimiters are permitted. - # Mainly used to detect premature termination of commands. - # - :always: The word 'always' in the «{ foo } always { bar }» syntax. - # - # When the kind of a word is not yet known, $this_word / $next_word may contain - # multiple states. For example, after "sudo -i", the next word may be either - # another --flag or a command name, hence the state would include both :start: - # and :sudo_opt:. - # - # The tokens are always added with both leading and trailing colons to serve as - # word delimiters (an improvised array); [[ $x == *:foo:* ]] and x=${x//:foo:/} - # will DTRT regardless of how many elements or repetitions $x has.. - # - # Handling of redirections: upon seeing a redirection token, we must stall - # the current state --- that is, the value of $this_word --- for two iterations - # (one for the redirection operator, one for the word following it representing - # the redirection target). Therefore, we set $in_redirection to 2 upon seeing a - # redirection operator, decrement it each iteration, and stall the current state - # when it is non-zero. Thus, upon reaching the next word (the one that follows - # the redirection operator and target), $this_word will still contain values - # appropriate for the word immediately following the word that preceded the - # redirection operator. - # - # The "the previous word was a redirection operator" state is not communicated - # to the next iteration via $next_word/$this_word as usual, but via - # $in_redirection. The value of $next_word from the iteration that processed - # the operator is discarded. - # - - # Processing buffer - local proc_buf="$buf" needle - for arg in ${interactive_comments-${(z)buf}} \ - ${interactive_comments+${(zZ+c+)buf}}; do - # Initialize $next_word to its default value? - (( in_redirection )) && (( --in_redirection )) - (( in_redirection == 0 )) && next_word=2 # else Stall $next_word. - - # Initialize per-"simple command" [zshmisc(1)] variables: - # - # $already_added (see next paragraph) - # $style how to highlight $arg - # $in_array_assignment boolean flag for "between '(' and ')' of array assignment" - # $highlight_glob boolean flag for "'noglob' is in effect" - # - # $already_added is set to 1 to disable adding an entry to region_highlight - # for this iteration. Currently, that is done for "" and $'' strings, - # which add the entry early so escape sequences within the string override - # the string's color. - already_added=0 - style=unknown-token - if (( this_word & 1 )); then - in_array_assignment=0 - [[ $arg == 'noglob' ]] && highlight_glob=0 - fi - - # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. - if [[ $arg == ';' ]] ; then - # We're looking for either a semicolon or a newline, whichever comes - # first. Both of these are rendered as a ";" (SEPER) by the ${(z)..} - # flag. - # - # We can't use the (Z+n+) flag because that elides the end-of-command - # token altogether, so 'echo foo\necho bar' (two commands) becomes - # indistinguishable from 'echo foo echo bar' (one command with three - # words for arguments). - needle=$'[;\n]' - offset=$(( ${proc_buf[(i)$needle]} - 1 )) - (( start_pos += offset )) - (( end_pos = start_pos + $#arg )) - - # Do not run default code for case when there is a new line - # It shouldn't be treated as ';', i.e. shouldn't be highlighted - # as unknown-token when appears after command-starting arg like "{" - if [[ "${proc_buf[offset+1]}" = $'\n' ]]; then - (( in_array_assignment )) && (( this_word = 2 )) || { (( this_word = 1 )); highlight_glob=1; } - in_redirection=0 - proc_buf="${proc_buf[offset + $#arg + 1,len]}" - start_pos=$end_pos - continue - else - # One more short path – for ';' command separator - (( in_array_assignment )) && (( this_word = 2 )) || { (( this_word = 1 )); highlight_glob=1; } - in_redirection=0 - [[ "${FAST_HIGHLIGHT_STYLES[commandseparator]}" != "none" ]] && (( start=start_pos-${#PREBUFFER}, end=end_pos-${#PREBUFFER}, start >= 0 )) && reply+=("$start $end ${FAST_HIGHLIGHT_STYLES[commandseparator]}") - proc_buf="${proc_buf[offset + $#arg + 1,len]}" - start_pos=$end_pos - continue - fi - - arg_type=3 - else - offset=0 - if [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\[[:space:]])##)* ]]; then - # The first, outer parenthesis - offset="${mend[1]}" - fi - ((start_pos+=offset)) - ((end_pos=start_pos+${#arg})) - - # No-hit will result in value 0 - arg_type=${__FAST_HIGHLIGHT_TOKEN_TYPES[$arg]} - fi - - proc_buf="${proc_buf[offset + $#arg + 1,len]}" - - # Handle the INTERACTIVE_COMMENTS option. - # - # We use the (Z+c+) flag so the entire comment is presented as one token in $arg. - if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then - if (( this_word & 3 )); then - style=comment - else - style=unknown-token # prematurely terminated - fi - # ADD - (( start=start_pos-${#PREBUFFER}, end=end_pos-${#PREBUFFER}, start >= 0 )) && reply+=("$start $end ${FAST_HIGHLIGHT_STYLES[$style]}") - start_pos=$end_pos - continue - fi - - # Analyse the current word. - if [[ $arg == (<0-9>|)(\<|\>)* ]] && [[ $arg != (\<|\>)$'\x28'* ]]; then - # A '<' or '>', possibly followed by a digit - in_redirection=2 - fi - - # Special-case the first word after 'sudo'. - if (( ! in_redirection )); then - if (( this_word & 4 )) && [[ $arg != -* ]]; then - (( this_word = this_word ^ 4 )) - fi - - # Parse the sudo command line - if (( this_word & 4 )); then - case "$arg" in - # Flag that requires an argument - '-'[Cgprtu]) - (( this_word & 1 )) && (( this_word = this_word ^ 1 )) - (( next_word = 8 )) - ;; - # This prevents misbehavior with sudo -u -otherargument - '-'*) - (( this_word & 1 )) && (( this_word = this_word ^ 1 )) - (( next_word = next_word | 1 )) - (( next_word = next_word | 4 )) - ;; - *) ;; - esac - elif (( this_word & 8 )); then - (( next_word = next_word | 4 )) - (( next_word = next_word | 1 )) - fi - fi - - expanded_path="" - - # The Great Fork: is this a command word? Is this a non-command word? - if (( this_word & 16 )) && [[ $arg == 'always' ]]; then - # try-always construct - style=reserved-word # de facto a reserved word, although not de jure - (( next_word = 1 )) - elif (( this_word & 1 )) && (( in_redirection == 0 )); then # $arg is the command word - cur_cmd="$arg" - if (( arg_type == 1 )); then - style=precommand - elif [[ "$arg" = "sudo" ]]; then - style=precommand - (( next_word & 2 )) && (( next_word = next_word ^ 2 )) - (( next_word = next_word | 4 )) - (( next_word = next_word | 1 )) - else - # Special-case: command word is '$foo', like that, without braces or anything. - # - # That's not entirely correct --- if the parameter's value happens to be a reserved - # word, the parameter expansion will be highlighted as a reserved word --- but that - # incorrectness is outweighed by the usability improvement of permitting the use of - # parameters that refer to commands, functions, and builtins. - if [[ ${arg[1]} == \$ ]] && (( ${+parameters} )) && [[ ${arg:1} = (#m)([a-zA-Z_][a-zA-Z0-9_]#|[0-9]##) ]] && (( ${+parameters[${MATCH}]} )); then - -fast-highlight-main-type ${(P)MATCH} - else - : ${expanded_path::=${(Q)~arg}} - -fast-highlight-main-type $expanded_path - fi - - case $REPLY in - reserved) # reserved word - style=reserved-word - if [[ $arg == $'\x7b' ]]; then - braces_stack='Y'"$braces_stack" - elif [[ $arg == $'\x7d' && $braces_stack[1] == "Y" ]]; then - # We're at command word, so no need to check right_brace_is_recognised_everywhere - braces_stack[1]="" - style=reserved-word - (( next_word = next_word | 16 )) - elif [[ $arg == "[[" ]]; then - braces_stack='A'"$braces_stack" - fi - ;; - 'suffix alias') style=suffix-alias;; - alias) - insane_alias=0 - case $arg in - # Issue #263: aliases with '=' on their LHS. - # - # There are three cases: - # - # - Unsupported, breaks 'alias -L' output, but invokable: - ('='*) :;; - # - Unsupported, not invokable: - (*'='*) insane_alias=1;; - # - The common case: - (*) :;; - esac - if (( insane_alias )); then - style=unknown-token - else - style=alias - zmodload -e zsh/parameter && alias_target=${aliases[$arg]} || alias_target="${"$(alias -- $arg)"#*=}" - [[ ${__FAST_HIGHLIGHT_TOKEN_TYPES[$alias_target]} = "1" && "$arg_type" != "1" ]] && __FAST_HIGHLIGHT_TOKEN_TYPES[$arg]="1" - fi - ;; - builtin) style=builtin;; - function) style=function;; - command) style=command;; - hashed) style=hashed-command;; - dirpath) style=path;; - none) # Assign? - if [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[[^\]]#\])(|[+])=* ]] || [[ $arg == [0-9]##(|[+])=* ]]; then - style=assign - # Assignment to a scalar parameter or to array - # (For array assignments, the command doesn't start until the ")" token.) - [[ $arg[-1] == '(' ]] && in_array_assignment=1 || (( next_word = next_word | 1 )) - elif [[ $arg[1] = $histchars[1] && -n "${arg[2]}" ]]; then - style=history-expansion - elif [[ $arg[1] == $histchars[2] ]]; then - style=history-expansion - elif (( arg_type == 3 )); then - # This highlights empty commands (semicolon follows nothing) as an error. - # Zsh accepts them, though. - (( this_word & 2 )) && style=commandseparator - elif [[ $arg[1,2] == '((' ]]; then - # Arithmetic evaluation. - # - # Note: prior to zsh-5.1.1-52-g4bed2cf (workers/36669), the ${(z)...} - # splitter would only output the '((' token if the matching '))' had - # been typed. Therefore, under those versions of zsh, BUFFER="(( 42" - # would be highlighted as an error until the matching "))" are typed. - # - # We highlight just the opening parentheses, as a reserved word; this - # is how [[ ... ]] is highlighted, too. - - # ADD - (( start=start_pos-${#PREBUFFER}, end=end_pos-${#PREBUFFER}, start >= 0 )) && reply+=("$start $(( start + 2 )) ${FAST_HIGHLIGHT_STYLES[reserved-word]}") - already_added=1 - # ADD - [[ $arg[-2,-1] == '))' ]] && (( start=start_pos-${#PREBUFFER}, end=end_pos-${#PREBUFFER}, start >= 0 )) && reply+=("$(( end - 2 )) $end ${FAST_HIGHLIGHT_STYLES[reserved-word]}") - elif [[ $arg == '()' ]]; then - # anonymous function - style=reserved-word - elif [[ $arg == $'\x28' ]]; then - # subshell - style=reserved-word - braces_stack='R'"$braces_stack" - elif [[ $arg == $'\x29' ]]; then - [[ $braces_stack[1] == "R" ]] && { braces_stack[1]=""; style=reserved-word; } - elif (( this_word & 14 )); then - style=default - fi - ;; - *) - # ADD - # (( start=start_pos-${#PREBUFFER}, end=end_pos-${#PREBUFFER}, start >= 0 )) && reply+=("$start $end commandtypefromthefuture-$REPLY") - already_added=1 - ;; - esac - fi - # in_redirection || BIT_regular || BIT_sudo_opt || BIT_sudo_arg - elif (( in_redirection + this_word & 14 )) - then # $arg is a non-command word - case $arg in - ']]') - style=reserved-word - [[ $braces_stack[1] == "A" ]] && braces_stack[1]="" - ;; - ']') - style=builtin - ;; - $'\x28') - # '(' inside [[ - style=reserved-word - braces_stack='R'"$braces_stack" - ;; - $'\x29') # subshell or end of array assignment - if (( in_array_assignment )); then - style=assign - in_array_assignment=0 - (( next_word = next_word | 1 )) - elif [[ $braces_stack[1] == "R" ]]; then - braces_stack[1]="" - style=reserved-word - fi;; - $'\x28\x29') # possibly a function definition - # || false # TODO: or if the previous word was a command word - (( FAST_HIGHLIGHT[multi_func_def] )) && (( next_word = next_word | 1 )) - style=reserved-word - # Remove possible annoying unknown-token style, or misleading function style - reply[-1]=() - ;; - '--'*) style=double-hyphen-option;; - '-'*) style=single-hyphen-option;; - "'"*) style=single-quoted-argument;; - '"'*) - # ADD - (( start=start_pos-${#PREBUFFER}, end=end_pos-${#PREBUFFER}, start >= 0 )) && reply+=("$start $end ${FAST_HIGHLIGHT_STYLES[double-quoted-argument]}") - -fast-highlight-string - already_added=1 - ;; - \$\'*) - # ADD - (( start=start_pos-${#PREBUFFER}, end=end_pos-${#PREBUFFER}, start >= 0 )) && reply+=("$start $end ${FAST_HIGHLIGHT_STYLES[dollar-quoted-argument]}") - -fast-highlight-dollar-string - already_added=1 - ;; - \$[^\(]*) - style=variable - ;; - '`'*) style=back-quoted-argument;; - [*?]*|*[^\\][*?]*) - (( highlight_glob )) && style=globbing || style=default;; - *) if [[ $arg = $'\x7d' && $braces_stack[1] == "Y" && "$FAST_HIGHLIGHT[right_brace_is_recognised_everywhere]" = "1" ]]; then - # right brace - # Parsing rule: # { - # - # Additionally, `tt(})' is recognized in any position if neither the - # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.""" - braces_stack[1]="" - style=reserved-word - (( next_word = next_word | 16 )) - elif [[ $arg[1] = $histchars[1] && -n "${arg[2]}" ]]; then - style=history-expansion - elif (( arg_type == 3 )); then - style=commandseparator - elif (( in_redirection == 2 )); then - style=redirection - else - if [[ -z "${FAST_HIGHLIGHT[no_check_paths]}" ]] && -fast-highlight-check-path; then - # ADD - (( start=start_pos-${#PREBUFFER}, end=end_pos-${#PREBUFFER}, start >= 0 )) && reply+=("$start $end ${FAST_HIGHLIGHT_STYLES[path]}") - already_added=1 - - [[ -n "$FAST_HIGHLIGHT_STYLES[path_pathseparator]" && "$FAST_HIGHLIGHT_STYLES[path]" != "$FAST_HIGHLIGHT_STYLES[path_pathseparator]" ]] && { - for (( pos = start_pos; pos <= end_pos; pos++ )) ; do - # ADD - [[ ${buf[pos]} == "/" ]] && (( start=pos-${#PREBUFFER}, start >= 0 )) && reply+=("$(( start - 1 )) $start ${FAST_HIGHLIGHT_STYLES[path_pathseparator]}") - done - } - else - style=default - fi - fi - ;; - esac - fi - - # ADD - (( already_added == 0 )) && [[ "${FAST_HIGHLIGHT_STYLES[$style]}" != "none" ]] && (( start=start_pos-${#PREBUFFER}, end=end_pos-${#PREBUFFER}, start >= 0 )) && reply+=("$start $end ${FAST_HIGHLIGHT_STYLES[$style]}") - - if (( arg_type == 3 )); then - if [[ $arg == ';' ]] && (( in_array_assignment )); then - # literal newline inside an array assignment - (( next_word = 2 )) - elif [[ -n "${braces_stack[(r)A]}" ]]; then - (( next_word = 2 )) - else - (( next_word = 1 )) - highlight_glob=1 - fi - elif (( arg_type == 1 || arg_type == 2 )) && (( this_word & 1 )); then - (( next_word = 1 )) - elif [[ $arg == "repeat" ]] && (( this_word & 1 )); then - # skip the repeat-count word - in_redirection=2 - # The redirection mechanism assumes $this_word describes the word - # following the redirection. Make it so. - # - # That word can be a command word with shortloops (`repeat 2 ls`) - # or a command separator (`repeat 2; ls` or `repeat 2; do ls; done`). - # - # The repeat-count word will be handled like a redirection target. - (( this_word = 3 )) - fi - start_pos=$end_pos - # This is the default/common codepath. - (( in_redirection == 0 )) && (( this_word = next_word )) #else # Stall $this_word. - done - - return 0 -} - -# Check if $arg is a path. -# If yes, return 0 and in $REPLY the style to use. -# Else, return non-zero (and the contents of $REPLY is undefined). --fast-highlight-check-path() -{ - : ${expanded_path:=${(Q)~arg}} - - [[ -z $expanded_path ]] && return 1 - [[ -e $expanded_path ]] && return 0 - - # Search the path in CDPATH, only for CD command - [[ "$cur_cmd" = "cd" ]] && for cdpath_dir in $cdpath ; do - [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 - done - - # It's not a path. - return 1 -} - -# Highlight special chars inside double-quoted strings --fast-highlight-string() -{ - mybuf="$arg" - idx=start_pos - - while [[ "$mybuf" = (#b)[^\$\\]#((\$(#B)([a-zA-Z_:][a-zA-Z0-9_:]#|[0-9]##)(#b)(\[[^\]]#\])(#c0,1))|(\$[{](\([a-zA-Z0@%#]##\))(#c0,1)[a-zA-Z0-9_:#]##(\[[^\]]#\])(#c0,1)[}])|[\\][\'\"\$]|[\\](*))(*) ]]; do - [[ -n "${match[7]}" ]] && { - # Skip following char – it is quoted. Choice is - # made to not highlight such quoting - idx+=${mbegin[1]}+1 - mybuf="${match[7]:1}" - } || { - idx+=${mbegin[1]}-1 - end_idx=idx+${mend[1]}-${mbegin[1]}+1 - mybuf="${match[8]}" - - # ADD - (( start=idx-${#PREBUFFER}, end=end_idx-${#PREBUFFER}, start >= 0 )) && reply+=("$start $end ${FAST_HIGHLIGHT_STYLES[back-or-dollar-double-quoted-argument]}") - - idx=end_idx - } - done -} - -# Highlight special chars inside dollar-quoted strings --fast-highlight-dollar-string() -{ - local i j k style - local AA - integer c - # Starting dollar-quote is at 1:2, so start parsing at offset 3 in the string. - for (( i = 3 ; i < end_pos - start_pos ; i += 1 )) ; do - (( j = i + start_pos - 1 )) - (( k = j + 1 )) - case "$arg[$i]" in - "\\") style=back-dollar-quoted-argument - for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )); do - [[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break - done - AA=$arg[$i+1,$c-1] - # Matching for HEX and OCT values like \0xA6, \xA6 or \012 - if [[ "$AA" =~ "^(x|X)[0-9a-fA-F]{1,2}" - || "$AA" =~ "^[0-7]{1,3}" - || "$AA" =~ "^u[0-9a-fA-F]{1,4}" - || "$AA" =~ "^U[0-9a-fA-F]{1,8}" - ]]; then - (( k += $#MATCH )) - (( i += $#MATCH )) - else - if (( $#arg > $i+1 )) && [[ $arg[$i+1] == [xXuU] ]]; then - # \x not followed by hex digits is probably an error - style=unknown-token - fi - (( k += 1 )) # Color following char too. - (( i += 1 )) # Skip parsing the escaped char. - fi - ;; - *) continue ;; - - esac - # ADD - (( start=j-${#PREBUFFER}, end=k-${#PREBUFFER}, start >= 0 )) && reply+=("$start $end ${FAST_HIGHLIGHT_STYLES[$style]}") - done -} - -# ------------------------------------------------------------------------------------------------- -# Main highlighter initialization -# ------------------------------------------------------------------------------------------------- - --fast-highlight-init() { - __fast_highlight_main__command_type_cache=() -} - -# vim:ft=zsh:sw=2:sts=2 -# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- - diff --git a/lib/local/_desk b/lib/local/_desk deleted file mode 100644 index 2aeac44..0000000 --- a/lib/local/_desk +++ /dev/null @@ -1,34 +0,0 @@ -#compdef desk -#autoload - -_all_desks() { - desks=($(desk list --only-names)) -} - -local expl -local -a desks - -local -a _subcommands -_subcommands=( - 'help:Print a help message.' - 'init:Initialize your desk configuration.' - 'list:List available desks' - 'ls:List available desks' - 'edit:Edit or create a desk, defaults to current desk' - 'go:Activate a desk' - '.:Activate a desk' - 'run:Run a command within a desk environment' - 'version:Show the desk version.' -) - -if (( CURRENT == 2 )); then - _describe -t commands 'desk subcommand' _subcommands - return -fi - -case "$words[2]" in - go|.|edit|run) - _all_desks - _wanted desks expl 'desks' compadd -a desks ;; -esac - diff --git a/lib/local/_docker b/lib/local/_docker deleted file mode 100644 index 01aaa8f..0000000 --- a/lib/local/_docker +++ /dev/null @@ -1,2755 +0,0 @@ -#compdef docker dockerd -# -# zsh completion for docker (http://docker.com) -# -# version: 0.3.0 -# github: https://github.com/felixr/docker-zsh-completion -# -# contributors: -# - Felix Riedel -# - Steve Durrheimer -# - Vincent Bernat -# -# license: -# -# Copyright (c) 2013, Felix Riedel -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of the nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -# Short-option stacking can be enabled with: -# zstyle ':completion:*:*:docker:*' option-stacking yes -# zstyle ':completion:*:*:docker-*:*' option-stacking yes -__docker_arguments() { - if zstyle -t ":completion:${curcontext}:" option-stacking; then - print -- -s - fi -} - -__docker_get_containers() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local kind type line s - declare -a running stopped lines args names - - kind=$1; shift - type=$1; shift - [[ $kind = (stopped|all) ]] && args=($args -a) - - lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line - lines=(${lines[2,-1]}) - - # Container ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}" - s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" - s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" - if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then - stopped=($stopped $s) - else - running=($running $s) - fi - done - fi - - # Names: we only display the one without slash. All other names - # are generated and may clutter the completion. However, with - # Swarm, all names may be prefixed by the swarm node name. - if [[ $type = (names|all) ]]; then - for line in $lines; do - names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}}) - # First step: find a common prefix and strip it (swarm node case) - (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/} - # Second step: only keep the first name without a / - s=${${names:#*/*}[1]} - # If no name, well give up. - (( $#s != 0 )) || continue - s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" - s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" - if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then - stopped=($stopped $s) - else - running=($running $s) - fi - done - fi - - [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0 - [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0 - return ret -} - -__docker_complete_stopped_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers stopped all "$@" -} - -__docker_complete_running_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers running all "$@" -} - -__docker_complete_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all all "$@" -} - -__docker_complete_containers_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all ids "$@" -} - -__docker_complete_containers_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all names "$@" -} - -__docker_complete_info_plugins() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - emulate -L zsh - setopt extendedglob - local -a plugins - plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: }) - _describe -t plugins "$1 plugins" plugins && ret=0 - return ret -} - -__docker_complete_images() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a images - images=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) - _describe -t docker-images "images" images && ret=0 - __docker_complete_repositories_with_tags && ret=0 - return ret -} - -__docker_complete_repositories() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a repos - repos=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}%% *}[2,-1]}) - repos=(${repos#}) - _describe -t docker-repos "repositories" repos && ret=0 - return ret -} - -__docker_complete_repositories_with_tags() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a repos onlyrepos matched - declare m - repos=(${${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/ ##/:::}%% *}) - repos=(${${repos%:::}#}) - # Check if we have a prefix-match for the current prefix. - onlyrepos=(${repos%::*}) - for m in $onlyrepos; do - [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { - # Yes, complete with tags - repos=(${${repos/:::/:}/:/\\:}) - _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 - return ret - } - done - # No, only complete repositories - onlyrepos=(${${repos%:::*}/:/\\:}) - _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 - - return ret -} - -__docker_search() { - [[ $PREFIX = -* ]] && return 1 - local cache_policy - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy - fi - - local searchterm cachename - searchterm="${words[$CURRENT]%/}" - cachename=_docker-search-$searchterm - - local expl - local -a result - if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ - && ! _retrieve_cache ${cachename#_}; then - _message "Searching for ${searchterm}..." - result=(${${${(f)${:-"$(_call_program commands docker $docker_options search $searchterm)"$'\n'}}%% *}[2,-1]}) - _store_cache ${cachename#_} result - fi - _wanted dockersearch expl 'available images' compadd -a result -} - -__docker_get_log_options() { - [[ $PREFIX = -* ]] && return 1 - - integer ret=1 - local log_driver=${opt_args[--log-driver]:-"all"} - local -a awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options - - awslogs_options=("awslogs-region" "awslogs-group" "awslogs-stream") - fluentd_options=("env" "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "labels" "tag") - gcplogs_options=("env" "gcp-log-cmd" "gcp-project" "labels") - gelf_options=("env" "gelf-address" "gelf-compression-level" "gelf-compression-type" "labels" "tag") - journald_options=("env" "labels" "tag") - json_file_options=("env" "labels" "max-file" "max-size") - logentries_options=("logentries-token") - syslog_options=("env" "labels" "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag") - splunk_options=("env" "labels" "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag") - - [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 - [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 - [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0 - [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 - [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 - [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 - [[ $log_driver = (logentries|all) ]] && _describe -t logentries-options "logentries options" logentries_options "$@" && ret=0 - [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 - [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 - - return ret -} - -__docker_complete_log_drivers() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog) - _describe -t log-drivers "log drivers" drivers && ret=0 - return ret -} - -__docker_complete_log_options() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (syslog-format) - syslog_format_opts=('rfc3164' 'rfc5424' 'rfc5424micro') - _describe -t syslog-format-opts "Syslog format Options" syslog_format_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - __docker_get_log_options -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_detach_keys() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - compset -P "*," - keys=(${:-{a-z}}) - ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}}) - _describe -t detach_keys "[a-z]" keys -qS "," && ret=0 - _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0 -} - -__docker_complete_pid() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local -a opts vopts - - opts=('host') - vopts=('container') - - if compset -P '*:'; then - case "${${words[-1]%:*}#*=}" in - (container) - __docker_complete_running_containers && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0 - _describe -t pid-opts "PID Options" opts && ret=0 - fi - - return ret -} - -__docker_complete_runtimes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - emulate -L zsh - setopt extendedglob - local -a runtimes_opts - runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}}) - _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0 -} - -__docker_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (ancestor) - __docker_complete_images && ret=0 - ;; - (before|since) - __docker_complete_containers && ret=0 - ;; - (health) - health_opts=('healthy' 'none' 'starting' 'unhealthy') - _describe -t health-filter-opts "health filter options" health_opts && ret=0 - ;; - (id) - __docker_complete_containers_ids && ret=0 - ;; - (is-task) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - (name) - __docker_complete_containers_names && ret=0 - ;; - (network) - __docker_complete_networks && ret=0 - ;; - (status) - status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing') - _describe -t status-filter-opts "status filter options" status_opts && ret=0 - ;; - (volume) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('ancestor' 'before' 'exited' 'health' 'id' 'label' 'name' 'network' 'since' 'status' 'volume') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_search_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a boolean_opts opts - - boolean_opts=('true' 'false') - opts=('is-automated' 'is-official' 'stars') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (is-automated|is-official) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_images_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a boolean_opts opts - - boolean_opts=('true' 'false') - opts=('before' 'dangling' 'label' 'reference' 'since') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (before|reference|since) - __docker_complete_images && ret=0 - ;; - (dangling) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_events_filter() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a opts - - opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'type' 'volume') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (container) - __docker_complete_containers && ret=0 - ;; - (daemon) - emulate -L zsh - setopt extendedglob - local -a daemon_opts - daemon_opts=( - ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}} - ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:} - ) - _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0 - ;; - (event) - local -a event_opts - event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disconnect' 'exec_create' 'exec_detach' - 'exec_start' 'export' 'health_status' 'import' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'rename' 'resize' 'restart' 'save' 'start' - 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update') - _describe -t event-filter-opts "event filter options" event_opts && ret=0 - ;; - (image) - __docker_complete_images && ret=0 - ;; - (network) - __docker_complete_networks && ret=0 - ;; - (type) - local -a type_opts - type_opts=('container' 'daemon' 'image' 'network' 'volume') - _describe -t type-filter-opts "type filter options" type_opts && ret=0 - ;; - (volume) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -# BO container - -__docker_container_commands() { - local -a _docker_container_subcommands - _docker_container_subcommands=( - "attach:Attach to a running container" - "commit:Create a new image from a container's changes" - "cp:Copy files/folders between a container and the local filesystem" - "create:Create a new container" - "diff:Inspect changes on a container's filesystem" - "exec:Run a command in a running container" - "export:Export a container's filesystem as a tar archive" - "inspect:Display detailed information on one or more containers" - "kill:Kill one or more running containers" - "logs:Fetch the logs of a container" - "ls:List containers" - "pause:Pause all processes within one or more containers" - "port:List port mappings or a specific mapping for the container" - "prune:Remove all stopped containers" - "rename:Rename a container" - "restart:Restart one or more containers" - "rm:Remove one or more containers" - "run:Run a command in a new container" - "start:Start one or more stopped containers" - "stats:Display a live stream of container(s) resource usage statistics" - "stop:Stop one or more running containers" - "top:Display the running processes of a container" - "unpause:Unpause all processes within one or more containers" - "update:Update configuration of one or more containers" - "wait:Block until one or more containers stop, then print their exit codes" - ) - _describe -t docker-container-commands "docker container command" _docker_container_subcommands -} - -__docker_container_subcommand() { - local -a _command_args opts_help opts_attach_exec_run_start opts_create_run opts_create_run_update - local expl help="--help" - integer ret=1 - - opts_attach_exec_run_start=( - "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys" - ) - opts_create_run=( - "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" - "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " - "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " - "($help)*--cap-add=[Add Linux capabilities]:capability: " - "($help)*--cap-drop=[Drop Linux capabilities]:capability: " - "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " - "($help)--cidfile=[Write the container ID to the file]:CID file:_files" - "($help)--cpus=[Number of CPUs (default 0.000)]:cpus: " - "($help)*--device=[Add a host device to the container]:device:_files" - "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " - "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " - "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " - "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " - "($help)--disable-content-trust[Skip image verification]" - "($help)*--dns=[Custom DNS servers]:DNS server: " - "($help)*--dns-option=[Custom DNS options]:DNS option: " - "($help)*--dns-search=[Custom DNS search domains]:DNS domains: " - "($help)*"{-e=,--env=}"[Environment variables]:environment variable: " - "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " - "($help)*--env-file=[Read environment variables from a file]:environment file:_files" - "($help)*--expose=[Expose a port from the container without publishing it]: " - "($help)*--group=[Set one or more supplementary user groups for the container]:group:_groups" - "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" - "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" - "($help)--ip=[Container IPv4 address]:IPv4: " - "($help)--ip6=[Container IPv6 address]:IPv6: " - "($help)--ipc=[IPC namespace to use]:IPC namespace: " - "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" - "($help)*--link=[Add link to another container]:link:->link" - "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " - "($help)*"{-l=,--label=}"[Container metadata]:label: " - "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" - "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_complete_log_options" - "($help)--mac-address=[Container MAC address]:MAC address: " - "($help)--name=[Container name]:name: " - "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" - "($help)*--network-alias=[Add network-scoped alias for the container]:alias: " - "($help)--oom-kill-disable[Disable OOM Killer]" - "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" - "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" - "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" - "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" - "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid" - "($help)--privileged[Give extended privileges to this container]" - "($help)--read-only[Mount the container's root filesystem as read only]" - "($help)*--security-opt=[Security options]:security option: " - "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " - "($help)--stop-timeout=[Timeout (in seconds) to stop a container]:time: " - "($help)*--sysctl=-[sysctl options]:sysctl: " - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" - "($help)*--ulimit=[ulimit options]:ulimit: " - "($help)--userns=[Container user namespace]:user namespace:(host)" - "($help)--tmpfs[mount tmpfs]" - "($help)*-v[Bind mount a volume]:volume: " - "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" - "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " - "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" - ) - opts_create_run_update=( - "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" - "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" - "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " - "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " - "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " - "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " - "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " - "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " - "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: " - "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " - "($help)--memory-reservation=[Memory soft limit]:Memory limit: " - "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " - "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" - ) - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (attach) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help)--no-stdin[Do not attach stdin]" \ - "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ - "($help -):containers:__docker_complete_running_containers" && ret=0 - ;; - (commit) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --author)"{-a=,--author=}"[Author]:author: " \ - "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ - "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ - "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ - "($help -):container:__docker_complete_containers" \ - "($help -): :__docker_complete_repositories_with_tags" && ret=0 - ;; - (cp) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \ - "($help -)1:container:->container" \ - "($help -)2:hostpath:_files" && ret=0 - case $state in - (container) - if compset -P "*:"; then - _files && ret=0 - else - __docker_complete_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (create) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_run \ - $opts_create_run_update \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (diff) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (exec) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ - "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " \ - "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ - "($help)--privileged[Give extended Linux capabilities to the command]" \ - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ - "($help -):containers:__docker_complete_running_containers" \ - "($help -)*::command:->anycommand" && ret=0 - case $state in - (anycommand) - shift 1 words - (( CURRENT-- )) - _normal && ret=0 - ;; - esac - ;; - (export) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -s --size)"{-s,--size}"[Display total file sizes]" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (kill) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (logs) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--details[Show extra details provided to logs]" \ - "($help -f --follow)"{-f,--follow}"[Follow log output]" \ - "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ - "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ - "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all containers]" \ - "($help)--before=[Show only container created before...]:containers:__docker_complete_containers" \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \ - "($help)--format=[Pretty-print containers using a Go template]:template: " \ - "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ - "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ - "($help -s --size)"{-s,--size}"[Display total file sizes]" \ - "($help)--since=[Show only containers created since...]:containers:__docker_complete_containers" && ret=0 - ;; - (pause|unpause) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (port) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:containers:__docker_complete_running_containers" \ - "($help -)2:port:_ports" && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rename) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):old name:__docker_complete_containers" \ - "($help -):new name: " && ret=0 - ;; - (restart) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ - "($help -)*:containers:__docker_complete_containers_ids" && ret=0 - ;; - (rm) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force removal]" \ - "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ - "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ - "($help -)*:containers:->values" && ret=0 - case $state in - (values) - if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then - __docker_complete_containers && ret=0 - else - __docker_complete_stopped_containers && ret=0 - fi - ;; - esac - ;; - (run) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_run \ - $opts_create_run_update \ - $opts_attach_exec_run_start \ - "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ - "($help)--health-cmd=[Command to run to check health]:command: " \ - "($help)--health-interval=[Time between running the check]:time: " \ - "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \ - "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \ - "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \ - "($help)--rm[Remove intermediate containers when it exits]" \ - "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \ - "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ - "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \ - "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - (storage-opt) - if compset -P "*="; then - _message "value" && ret=0 - else - opts=('size') - _describe -t filter-opts "storage options" opts -qS "=" && ret=0 - fi - ;; - esac - ;; - (start) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ - "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \ - "($help -)*:containers:__docker_complete_stopped_containers" && ret=0 - ;; - (stats) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ - "($help)--format=[Pretty-print images using a Go template]:template: " \ - "($help)--no-stream[Disable streaming stats and only pull the first result]" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (stop) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (top) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:containers:__docker_complete_running_containers" \ - "($help -)*:: :->ps-arguments" && ret=0 - case $state in - (ps-arguments) - _ps && ret=0 - ;; - esac - ;; - (update) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - opts_create_run_update \ - "($help -)*: :->values" && ret=0 - case $state in - (values) - if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then - __docker_complete_stopped_containers && ret=0 - else - __docker_complete_containers && ret=0 - fi - ;; - esac - ;; - (wait) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 - ;; - esac - - return ret -} - -# EO container - -# BO image - -__docker_image_commands() { - local -a _docker_image_subcommands - _docker_image_subcommands=( - "build:Build an image from a Dockerfile" - "history:Show the history of an image" - "import:Import the contents from a tarball to create a filesystem image" - "inspect:Display detailed information on one or more images" - "load:Load an image from a tar archive or STDIN" - "ls:List images" - "prune:Remove unused images" - "pull:Pull an image or a repository from a registry" - "push:Push an image or a repository to a registry" - "rm:Remove one or more images" - "save:Save one or more images to a tar archive (streamed to STDOUT by default)" - "tag:Tag an image into a repository" - ) - _describe -t docker-image-commands "docker image command" _docker_image_subcommands -} - -__docker_image_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (build) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--build-arg=[Build-time variables]:=: " \ - "($help)*--cache-from=[Images to consider as cache sources]: :__docker_complete_repositories_with_tags" \ - "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" \ - "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " \ - "($help)--compress[Compress the build context using gzip]" \ - "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " \ - "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " \ - "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " \ - "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " \ - "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " \ - "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " \ - "($help)--disable-content-trust[Skip image verification]" \ - "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ - "($help)--force-rm[Always remove intermediate containers]" \ - "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" \ - "($help)*--label=[Set metadata for an image]:label=value: " \ - "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " \ - "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " \ - "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" \ - "($help)--no-cache[Do not use cache when building the image]" \ - "($help)--pull[Attempt to pull a newer version of the image]" \ - "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ - "($help)--rm[Remove intermediate containers after a successful build]" \ - "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " \ - "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_complete_repositories_with_tags" \ - "($help)*--ulimit=[ulimit options]:ulimit: " \ - "($help)--userns=[Container user namespace]:user namespace:(host)" \ - "($help -):path or URL:_directories" && ret=0 - ;; - (history) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (import) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ - "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \ - "($help -):URL:(- http:// file://)" \ - "($help -): :__docker_complete_repositories_with_tags" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -)*:images:__docker_complete_images" && ret=0 - ;; - (load) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -i --input)"{-i=,--input=}"[Read from tar archive file]:archive file:_files -g \"*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)\"" \ - "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0 - ;; - (ls|list) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all images]" \ - "($help)--digests[Show digests]" \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \ - "($help)--format=[Pretty-print images using a Go template]:template: " \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ - "($help -): :__docker_complete_repositories" && ret=0 - case $state in - (filter-options) - __docker_complete_images_filters && ret=0 - ;; - esac - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Remove all unused images, not just dangling ones]" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (pull) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ - "($help)--disable-content-trust[Skip image verification]" \ - "($help -):name:__docker_search" && ret=0 - ;; - (push) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--disable-content-trust[Skip image signing]" \ - "($help -): :__docker_complete_images" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force removal]" \ - "($help)--no-prune[Do not delete untagged parents]" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (save) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (tag) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):source:__docker_complete_images"\ - "($help -):destination:__docker_complete_repositories_with_tags" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 - ;; - esac - - return ret -} - -# EO image - -# BO network - -__docker_network_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (driver) - __docker_complete_info_plugins Network && ret=0 - ;; - (id) - __docker_complete_networks_ids && ret=0 - ;; - (name) - __docker_complete_networks_names && ret=0 - ;; - (type) - type_opts=('builtin' 'custom') - _describe -t type-filter-opts "Type Filter Options" type_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('driver' 'id' 'label' 'name' 'type') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_get_networks() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines networks - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options network ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Network ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" - networks=($networks $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" - networks=($networks $s) - done - fi - - _describe -t networks-list "networks" networks "$@" && ret=0 - return ret -} - -__docker_complete_networks() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks all "$@" -} - -__docker_complete_networks_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks ids "$@" -} - -__docker_complete_networks_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks names "$@" -} - -__docker_network_commands() { - local -a _docker_network_subcommands - _docker_network_subcommands=( - "connect:Connect a container to a network" - "create:Creates a new network with a name specified by the user" - "disconnect:Disconnects a container from a network" - "inspect:Displays detailed information on a network" - "ls:Lists all the networks created by the user" - "prune:Remove all unused networks" - "rm:Deletes one or more networks" - ) - _describe -t docker-network-commands "docker network command" _docker_network_subcommands -} - -__docker_network_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (connect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--alias=[Add network-scoped alias for the container]:alias: " \ - "($help)--ip=[Container IPv4 address]:IPv4: " \ - "($help)--ip6=[Container IPv6 address]:IPv6: " \ - "($help)*--link=[Add a link to another container]:link:->link" \ - "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \ - "($help -)1:network:__docker_complete_networks" \ - "($help -)2:containers:__docker_complete_containers" && ret=0 - - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)--attachable[Enable manual container attachment]" \ - "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \ - "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ - "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \ - "($help)--internal[Restricts external access to the network]" \ - "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ - "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ - "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \ - "($help)--ipv6[Enable IPv6 networking]" \ - "($help)*--label=[Set metadata on a network]:label=value: " \ - "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \ - "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ - "($help -)1:Network Name: " && ret=0 - ;; - (disconnect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:network:__docker_complete_networks" \ - "($help -)2:containers:__docker_complete_containers" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -)*:network:__docker_complete_networks" && ret=0 - ;; - (ls) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--no-trunc[Do not truncate the output]" \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ - "($help)--format=[Pretty-print networks using a Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0 - case $state in - (filter-options) - __docker_network_complete_ls_filters && ret=0 - ;; - esac - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:network:__docker_complete_networks" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 - ;; - esac - - return ret -} - -# EO network - -# BO node - -__docker_node_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (id) - __docker_complete_nodes_ids && ret=0 - ;; - (membership) - membership_opts=('accepted' 'pending' 'rejected') - _describe -t membership-opts "membership options" membership_opts && ret=0 - ;; - (name) - __docker_complete_nodes_names && ret=0 - ;; - (role) - role_opts=('manager' 'worker') - _describe -t role-opts "role options" role_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'membership' 'name' 'role') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_node_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_nodes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines nodes args - - type=$1; shift - filter=$1; shift - [[ $filter != "none" ]] && args=("-f $filter") - - lines=(${(f)${:-"$(_call_program commands docker $docker_options node ls $args)"$'\n'}}) - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Node ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - nodes=($nodes $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - nodes=($nodes $s) - done - fi - - _describe -t nodes-list "nodes" nodes "$@" && ret=0 - return ret -} - -__docker_complete_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all none "$@" -} - -__docker_complete_nodes_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes ids none "$@" -} - -__docker_complete_nodes_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes names none "$@" -} - -__docker_complete_pending_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "membership=pending" "$@" -} - -__docker_complete_manager_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "role=manager" "$@" -} - -__docker_complete_worker_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "role=worker" "$@" -} - -__docker_node_commands() { - local -a _docker_node_subcommands - _docker_node_subcommands=( - "demote:Demote a node as manager in the swarm" - "inspect:Display detailed information on one or more nodes" - "ls:List nodes in the swarm" - "promote:Promote a node as manager in the swarm" - "rm:Remove one or more nodes from the swarm" - "ps:List tasks running on one or more nodes, defaults to current node" - "update:Update a node" - ) - _describe -t docker-node-commands "docker node command" _docker_node_subcommands -} - -__docker_node_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force remove a node from the swarm]" \ - "($help -)*:node:__docker_complete_pending_nodes" && ret=0 - ;; - (demote) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:node:__docker_complete_manager_nodes" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help)--pretty[Print the information in a human friendly format]" \ - "($help -)*:node:__docker_complete_nodes" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - case $state in - (filter-options) - __docker_node_complete_ls_filters && ret=0 - ;; - esac - ;; - (promote) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:node:__docker_complete_worker_nodes" && ret=0 - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Display all instances]" \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -)*:node:__docker_complete_nodes" && ret=0 - case $state in - (filter-options) - __docker_node_complete_ps_filters && ret=0 - ;; - esac - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--availability=[Availability of the node]:availability:(active pause drain)" \ - "($help)*--label-add=[Add or update a node label]:key=value: " \ - "($help)*--label-rm=[Remove a node label if exists]:label: " \ - "($help)--role=[Role of the node]:role:(manager worker)" \ - "($help -)1:node:__docker_complete_nodes" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0 - ;; - esac - - return ret -} - -# EO node - -# BO plugin - -__docker_complete_plugins() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines plugins - - lines=(${(f)${:-"$(_call_program commands docker $docker_options plugin ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Name - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}" - plugins=($plugins $s) - done - - _describe -t plugins-list "plugins" plugins "$@" && ret=0 - return ret -} - -__docker_plugin_commands() { - local -a _docker_plugin_subcommands - _docker_plugin_subcommands=( - "disable:Disable a plugin" - "enable:Enable a plugin" - "inspect:Return low-level information about a plugin" - "install:Install a plugin" - "ls:List plugins" - "push:Push a plugin" - "rm:Remove a plugin" - "set:Change settings for a plugin" - ) - _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands -} - -__docker_plugin_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (disable|enable|inspect|install|ls|push|rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:plugin:__docker_complete_plugins" && ret=0 - ;; - (set) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:plugin:__docker_complete_plugins" \ - "($help-)*:key=value: " && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0 - ;; - esac - - return ret -} - -# EO plugin - -# BO secret - -__docker_secrets() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines secrets - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options secret ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - secrets=($secrets $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - secrets=($secrets $s) - done - fi - - _describe -t secrets-list "secrets" secrets "$@" && ret=0 - return ret -} - -__docker_complete_secrets() { - [[ $PREFIX = -* ]] && return 1 - __docker_secrets all "$@" -} - -__docker_secret_commands() { - local -a _docker_secret_subcommands - _docker_secret_subcommands=( - "create:Create a secret using stdin as content" - "inspect:Display detailed information on one or more secrets" - "ls:List secrets" - "rm:Remove one or more secrets" - ) - _describe -t docker-secret-commands "docker secret command" _docker_secret_subcommands -} - -__docker_secret_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-l=,--label=}"[Secret labels]:label: " \ - "($help -):secret: " && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ - "($help -)*:secret:__docker_complete_secrets" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:secret:__docker_complete_secrets" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_secret_commands" && ret=0 - ;; - esac - - return ret -} - -# EO secret - -# BO service - -__docker_service_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (id) - __docker_complete_services_ids && ret=0 - ;; - (name) - __docker_complete_services_names && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_service_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_services() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines services - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options service ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Service ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" - services=($services $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" - services=($services $s) - done - fi - - _describe -t services-list "services" services "$@" && ret=0 - return ret -} - -__docker_complete_services() { - [[ $PREFIX = -* ]] && return 1 - __docker_services all "$@" -} - -__docker_complete_services_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_services ids "$@" -} - -__docker_complete_services_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_services names "$@" -} - -__docker_service_commands() { - local -a _docker_service_subcommands - _docker_service_subcommands=( - "create:Create a new service" - "inspect:Display detailed information on one or more services" - "ls:List services" - "rm:Remove one or more services" - "scale:Scale one or multiple replicated services" - "ps:List the tasks of a service" - "update:Update a service" - ) - _describe -t docker-service-commands "docker service command" _docker_service_subcommands -} - -__docker_service_subcommand() { - local -a _command_args opts_help opts_create_update - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - opts_create_update=( - "($help)*--constraint=[Placement constraints]:constraint: " - "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)" - "($help)*"{-e=,--env=}"[Set environment variables]:env: " - "($help)--health-cmd=[Command to run to check health]:command: " - "($help)--health-interval=[Time between running the check]:time: " - "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" - "($help)--health-timeout=[Maximum time to allow one check to run]:time: " - "($help)--hostname=[Service container hostname]:hostname: " \ - "($help)*--label=[Service labels]:label: " - "($help)--limit-cpu=[Limit CPUs]:value: " - "($help)--limit-memory=[Limit Memory]:value: " - "($help)--log-driver=[Logging driver for service]:logging driver:__docker_complete_log_drivers" - "($help)*--log-opt=[Logging driver options]:log driver options:__docker_complete_log_options" - "($help)*--mount=[Attach a filesystem mount to the service]:mount: " - "($help)*--network=[Network attachments]:network: " - "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" - "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: " - "($help)--replicas=[Number of tasks]:replicas: " - "($help)--reserve-cpu=[Reserve CPUs]:value: " - "($help)--reserve-memory=[Reserve Memory]:value: " - "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)" - "($help)--restart-delay=[Delay between restart attempts]:delay: " - "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: " - "($help)--restart-window=[Window used to evaluate the restart policy]:window: " - "($help)*--secret=[Specify secrets to expose to the service]:secret:__docker_complete_secrets" - "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: " - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-TTY]" - "($help)--update-delay=[Delay between updates]:delay: " - "($help)--update-failure-action=[Action on update failure]:mode:(pause continue)" - "($help)--update-max-failure-ratio=[Failure rate to tolerate during an update]:fraction: " - "($help)--update-monitor=[Duration after each task update to monitor for failure]:window: " - "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: " - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" - "($help)--with-registry-auth[Send registry authentication details to swarm agents]" - "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" - ) - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_update \ - "($help)*--container-label=[Container labels]:label: " \ - "($help)*--dns=[Set custom DNS servers]:DNS: " \ - "($help)*--dns-option=[Set DNS options]:DNS option: " \ - "($help)*--dns-search=[Set custom DNS search domains]:DNS search: " \ - "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ - "($help)--mode=[Service Mode]:mode:(global replicated)" \ - "($help)--name=[Service name]:name: " \ - "($help)*--publish=[Publish a port]:port: " \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help)--pretty[Print the information in a human friendly format]" \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:->filter-options" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - case $state in - (filter-options) - __docker_service_complete_ls_filters && ret=0 - ;; - esac - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (scale) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:service:->values" && ret=0 - case $state in - (values) - if compset -P '*='; then - _message 'replicas' && ret=0 - else - __docker_complete_services -qS "=" - fi - ;; - esac - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ - "($help -)1:service:__docker_complete_services" && ret=0 - case $state in - (filter-options) - __docker_service_complete_ps_filters && ret=0 - ;; - esac - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_update \ - "($help)--arg=[Service command args]:arguments: _normal" \ - "($help)*--container-label-add=[Add or update container labels]:label: " \ - "($help)*--container-label-rm=[Remove a container label by its key]:label: " \ - "($help)*--dns-add=[Add or update custom DNS servers]:DNS: " \ - "($help)*--dns-rm=[Remove custom DNS servers]:DNS: " \ - "($help)*--dns-option-add=[Add or update DNS options]:DNS option: " \ - "($help)*--dns-option-rm=[Remove DNS options]:DNS option: " \ - "($help)*--dns-search-add=[Add or update custom DNS search domains]:DNS search: " \ - "($help)*--dns-search-rm=[Remove DNS search domains]:DNS search: " \ - "($help)--force[Force update]" \ - "($help)*--group-add=[Add additional supplementary user groups to the container]:group:_groups" \ - "($help)*--group-rm=[Remove previously added supplementary user groups from the container]:group:_groups" \ - "($help)--image=[Service image tag]:image:__docker_complete_repositories" \ - "($help)*--publish-add=[Add or update a port]:port: " \ - "($help)*--publish-rm=[Remove a port(target-port mandatory)]:port: " \ - "($help)--rollback[Rollback to previous specification]" \ - "($help -)1:service:__docker_complete_services" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0 - ;; - esac - - return ret -} - -# EO service - -# BO stack - -__docker_stack_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_stack_complete_services_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_stacks() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines stacks - - lines=(${(f)${:-"$(_call_program commands docker $docker_options stack ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Service ID - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - stacks=($stacks $s) - done - - _describe -t stacks-list "stacks" stacks "$@" && ret=0 - return ret -} - -__docker_complete_stacks() { - [[ $PREFIX = -* ]] && return 1 - __docker_stacks "$@" -} - -__docker_stack_commands() { - local -a _docker_stack_subcommands - _docker_stack_subcommands=( - "deploy:Deploy a new stack or update an existing stack" - "ls:List stacks" - "ps:List the tasks in the stack" - "rm:Remove the stack" - "services:List the services in the stack" - ) - _describe -t docker-stack-commands "docker stack command" _docker_stack_subcommands -} - -__docker_stack_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (deploy|up) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--bundle-file=[Path to a Distributed Application Bundle file]:dab:_files -g \"*.dab\"" \ - "($help -c --compose-file)"{-c=,--compose-file=}"[Path to a Compose file]:compose file:_files -g \"*.(yml|yaml)\"" \ - "($help)--with-registry-auth[Send registry authentication details to Swarm agents]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help && ret=0 - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Display all tasks]" \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_ps_filters" \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (rm|remove|down) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (services) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_services_filters" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_stack_commands" && ret=0 - ;; - esac - - return ret -} - -# EO stack - -# BO swarm - -__docker_swarm_commands() { - local -a _docker_swarm_subcommands - _docker_swarm_subcommands=( - "init:Initialize a swarm" - "join:Join a swarm as a node and/or manager" - "join-token:Manage join tokens" - "leave:Leave a swarm" - "update:Update the swarm" - ) - _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands -} - -__docker_swarm_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (init) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--advertise-addr[Advertised address]:ip\:port: " \ - "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ - "($help)--force-new-cluster[Force create a new cluster from current state]" \ - "($help)--listen-addr=[Listen address]:ip\:port: " \ - "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ - "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ - "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 - ;; - (join) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--advertise-addr[Advertised address]:ip\:port: " \ - "($help)--listen-addr=[Listen address]:ip\:port: " \ - "($help)--token=[Token for entry into the swarm]:secret: " \ - "($help -):host\:port: " && ret=0 - ;; - (join-token) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ - "($help)--rotate[Rotate join token]" \ - "($help -):role:(manager worker)" && ret=0 - ;; - (leave) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force this node to leave the swarm, ignoring warnings]" && ret=0 - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ - "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ - "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ - "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ - "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ - "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 - ;; - esac - - return ret -} - -# EO swarm - -# BO system - -__docker_system_commands() { - local -a _docker_system_subcommands - _docker_system_subcommands=( - "df:Show docker filesystem usage" - "events:Get real time events from the server" - "info:Display system-wide information" - "prune:Remove unused data" - ) - _describe -t docker-system-commands "docker system command" _docker_system_subcommands -} - -__docker_system_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (df) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -v --verbose)"{-v,--verbose}"[Show detailed information on space usage]" && ret=0 - ;; - (events) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \ - "($help)--since=[Events created since this timestamp]:timestamp: " \ - "($help)--until=[Events created until this timestamp]:timestamp: " \ - "($help)--format=[Format the output using the given go template]:template: " && ret=0 - ;; - (info) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Remove all unused data, not just dangling ones]" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 - ;; - esac - - return ret -} - -# EO system - -# BO volume - -__docker_volume_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (dangling) - dangling_opts=('true' 'false') - _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 - ;; - (driver) - __docker_complete_info_plugins Volume && ret=0 - ;; - (name) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('dangling' 'driver' 'label' 'name') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_volumes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a lines volumes - - lines=(${(f)${:-"$(_call_program commands docker $docker_options volume ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Names - local line s - for line in $lines; do - s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - volumes=($volumes $s) - done - - _describe -t volumes-list "volumes" volumes && ret=0 - return ret -} - -__docker_volume_commands() { - local -a _docker_volume_subcommands - _docker_volume_subcommands=( - "create:Create a volume" - "inspect:Display detailed information on one or more volumes" - "ls:List volumes" - "prune:Remove all unused volumes" - "rm:Remove one or more volumes" - ) - _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands -} - -__docker_volume_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \ - "($help)*--label=[Set metadata for a volume]:label=value: " \ - "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \ - "($help -)1:Volume name: " && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -)1:volume:__docker_complete_volumes" && ret=0 - ;; - (ls) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ - "($help)--format=[Pretty-print volumes using a Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 - case $state in - (filter-options) - __docker_volume_complete_ls_filters && ret=0 - ;; - esac - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \ - "($help -):volume:__docker_complete_volumes" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 - ;; - esac - - return ret -} - -# EO volume - -__docker_caching_policy() { - oldp=( "$1"(Nmh+1) ) # 1 hour - (( $#oldp )) -} - -__docker_commands() { - local cache_policy - - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy - fi - - if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \ - && ! _retrieve_cache docker_subcommands; - then - local -a lines - lines=(${(f)"$(_call_program commands docker 2>&1)"}) - _docker_subcommands=(${${${(M)${lines[$((${lines[(i)*Commands:]} + 1)),-1]}:# *}## #}/ ##/:}) - _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') - (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands - fi - _describe -t docker-commands "docker command" _docker_subcommands -} - -__docker_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (attach|commit|cp|create|diff|exec|export|kill|logs|pause|unpause|port|rename|restart|rm|run|start|stats|stop|top|update|wait) - __docker_container_subcommand && ret=0 - ;; - (build|history|import|load|pull|push|save|tag) - __docker_image_subcommand && ret=0 - ;; - (container) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_container_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_container_subcommand && ret=0 - ;; - esac - ;; - (daemon) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \ - "($help)--api-cors-header=[CORS headers in the Engine API]:CORS headers: " \ - "($help)*--authorization-plugin=[Authorization plugins to load]" \ - "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ - "($help)--bip=[Network bridge IP]:IP address: " \ - "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \ - "($help)--cluster-advertise=[Address or interface name to advertise]:Instance to advertise (host\:port): " \ - "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \ - "($help)*--cluster-store-opt=[Cluster store options]:Cluster options:->cluster-store-options" \ - "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \ - "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ - "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ - "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ - "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ - "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \ - "($help)--disable-legacy-registry[Disable contacting legacy registries]" \ - "($help)*--dns=[DNS server to use]:DNS: " \ - "($help)*--dns-opt=[DNS options to use]:DNS option: " \ - "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ - "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \ - "($help)--exec-root=[Root directory for execution state files]:path:_directories" \ - "($help)--experimental[Enable experimental features]" \ - "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ - "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ - "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ - "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \ - "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ - "($help)--icc[Enable inter-container communication]" \ - "($help)--init-path=[Path to the docker-init binary]:docker-init binary:_files" \ - "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ - "($help)--ip=[Default IP when binding container ports]" \ - "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ - "($help)--ip-masq[Enable IP masquerading]" \ - "($help)--iptables[Enable addition of iptables rules]" \ - "($help)--ipv6[Enable IPv6 networking]" \ - "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ - "($help)*--label=[Key=value labels]:label: " \ - "($help)--live-restore[Enable live restore of docker when containers are still running]" \ - "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" \ - "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_complete_log_options" \ - "($help)--max-concurrent-downloads[Set the max concurrent downloads for each pull]" \ - "($help)--max-concurrent-uploads[Set the max concurrent uploads for each push]" \ - "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \ - "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \ - "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ - "($help)--raw-logs[Full timestamps without ANSI coloring]" \ - "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \ - "($help)--seccomp-profile=[Path to seccomp profile]:path:_files -g \"*.json\"" \ - "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs btrfs devicemapper overlay overlay2 vfs zfs)" \ - "($help)--selinux-enabled[Enable selinux support]" \ - "($help)--shutdown-timeout=[Set the shutdown timeout value in seconds]:time: " \ - "($help)*--storage-opt=[Storage driver options]:storage driver options: " \ - "($help)--tls[Use TLS]" \ - "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \ - "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \ - "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \ - "($help)--tlsverify[Use TLS and verify the remote]" \ - "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ - "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ - "($help)--userland-proxy-path=[Path to the userland proxy binary]:binary:_files" && ret=0 - - case $state in - (cluster-store) - if compset -P '*://'; then - _message 'host:port' && ret=0 - else - store=('consul' 'etcd' 'zk') - _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0 - fi - ;; - (cluster-store-options) - if compset -P '*='; then - _files && ret=0 - else - opts=('discovery.heartbeat' 'discovery.ttl' 'kv.cacertfile' 'kv.certfile' 'kv.keyfile' 'kv.path') - _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0 - fi - ;; - (users-groups) - if compset -P '*:'; then - _groups && ret=0 - else - _describe -t userns-default "default Docker user management" '(default)' && ret=0 - _users && ret=0 - fi - ;; - esac - ;; - (events|info) - __docker_system_subcommand && ret=0 - ;; - (image) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_image_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_image_subcommand && ret=0 - ;; - esac - ;; - (images) - words[1]='ls' - __docker_image_subcommand && ret=0 - ;; - (inspect) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ - "($help)--type=[Return JSON for specified type]:type:(container image network node plugin service volume)" \ - "($help -)*: :->values" && ret=0 - - case $state in - (values) - if [[ ${words[(r)--type=container]} == --type=container ]]; then - __docker_complete_containers && ret=0 - elif [[ ${words[(r)--type=image]} == --type=image ]]; then - __docker_complete_images && ret=0 - elif [[ ${words[(r)--type=network]} == --type=network ]]; then - __docker_complete_networks && ret=0 - elif [[ ${words[(r)--type=node]} == --type=node ]]; then - __docker_complete_nodes && ret=0 - elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then - __docker_complete_plugins && ret=0 - elif [[ ${words[(r)--type=service]} == --type=service ]]; then - __docker_complete_services && ret=0 - elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then - __docker_complete_volumes && ret=0 - else - __docker_complete_containers - __docker_complete_images - __docker_complete_networks - __docker_complete_nodes - __docker_complete_plugins - __docker_complete_services - __docker_complete_volumes && ret=0 - fi - ;; - esac - ;; - (login) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -p --password)"{-p=,--password=}"[Password]:password: " \ - "($help -u --user)"{-u=,--user=}"[Username]:username: " \ - "($help -)1:server: " && ret=0 - ;; - (logout) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:server: " && ret=0 - ;; - (network) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_network_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_network_subcommand && ret=0 - ;; - esac - ;; - (node) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_node_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_node_subcommand && ret=0 - ;; - esac - ;; - (plugin) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_plugin_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_plugin_subcommand && ret=0 - ;; - esac - ;; - (ps) - words[1]='ls' - __docker_container_subcommand && ret=0 - ;; - (rmi) - words[1]='rm' - __docker_image_subcommand && ret=0 - ;; - (search) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \ - "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -):term: " && ret=0 - - case $state in - (filter-options) - __docker_complete_search_filters && ret=0 - ;; - esac - ;; - (secret) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_secret_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_secret_subcommand && ret=0 - ;; - esac - ;; - (service) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_service_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_service_subcommand && ret=0 - ;; - esac - ;; - (stack) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_stack_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_stack_subcommand && ret=0 - ;; - esac - ;; - (swarm) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_swarm_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_swarm_subcommand && ret=0 - ;; - esac - ;; - (system) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_system_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_system_subcommand && ret=0 - ;; - esac - ;; - (version) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 - ;; - (volume) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_volume_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_volume_subcommand && ret=0 - ;; - esac - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 - ;; - esac - - return ret -} - -_docker() { - # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. - # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. - if [[ $service != docker ]]; then - _call_function - _$service - return - fi - - local curcontext="$curcontext" state line help="-h --help" - integer ret=1 - typeset -A opt_args - - _arguments $(__docker_arguments) -C \ - "(: -)"{-h,--help}"[Print usage]" \ - "($help)--config[Location of client config files]:path:_directories" \ - "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ - "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ - "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ - "($help)--tls[Use TLS]" \ - "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ - "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ - "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ - "($help)--tlsverify[Use TLS and verify the remote]" \ - "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ - "($help -v --version)"{-v,--version}"[Print version information and quit]" \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - local host=${opt_args[-H]}${opt_args[--host]} - local config=${opt_args[--config]} - local docker_options="${host:+--host $host} ${config:+--config $config}" - - case $state in - (command) - __docker_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-$words[1]: - __docker_subcommand && ret=0 - ;; - esac - - return ret -} - -_dockerd() { - integer ret=1 - words[1]='daemon' - __docker_subcommand && ret=0 - return ret -} - -_docker "$@" - -# Local Variables: -# mode: Shell-Script -# sh-indentation: 4 -# indent-tabs-mode: nil -# sh-basic-offset: 4 -# End: -# vim: ft=zsh sw=4 ts=4 et - diff --git a/lib/local/_docker-compose b/lib/local/_docker-compose deleted file mode 100644 index 3109301..0000000 --- a/lib/local/_docker-compose +++ /dev/null @@ -1,456 +0,0 @@ -#compdef docker-compose - -# Description -# ----------- -# zsh completion for docker-compose -# https://github.com/sdurrheimer/docker-compose-zsh-completion -# ------------------------------------------------------------------------- -# Version -# ------- -# 1.5.0 -# ------------------------------------------------------------------------- -# Authors -# ------- -# * Steve Durrheimer -# ------------------------------------------------------------------------- -# Inspiration -# ----------- -# * @albers docker-compose bash completion script -# * @felixr docker zsh completion script : https://github.com/felixr/docker-zsh-completion -# ------------------------------------------------------------------------- - -__docker-compose_q() { - docker-compose 2>/dev/null $compose_options "$@" -} - -# All services defined in docker-compose.yml -__docker-compose_all_services_in_compose_file() { - local already_selected - local -a services - already_selected=$(echo $words | tr " " "|") - __docker-compose_q config --services \ - | grep -Ev "^(${already_selected})$" -} - -# All services, even those without an existing container -__docker-compose_services_all() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - services=$(__docker-compose_all_services_in_compose_file) - _alternative "args:services:($services)" && ret=0 - - return ret -} - -# All services that have an entry with the given key in their docker-compose.yml section -__docker-compose_services_with_key() { - local already_selected - local -a buildable - already_selected=$(echo $words | tr " " "|") - # flatten sections to one line, then filter lines containing the key and return section name. - __docker-compose_q config \ - | sed -n -e '/^services:/,/^[^ ]/p' \ - | sed -n 's/^ //p' \ - | awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' \ - | grep " \+$1:" \ - | cut -d: -f1 \ - | grep -Ev "^(${already_selected})$" -} - -# All services that are defined by a Dockerfile reference -__docker-compose_services_from_build() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - buildable=$(__docker-compose_services_with_key build) - _alternative "args:buildable services:($buildable)" && ret=0 - - return ret -} - -# All services that are defined by an image -__docker-compose_services_from_image() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - pullable=$(__docker-compose_services_with_key image) - _alternative "args:pullable services:($pullable)" && ret=0 - - return ret -} - -__docker-compose_get_services() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local kind - declare -a running paused stopped lines args services - - docker_status=$(docker ps > /dev/null 2>&1) - if [ $? -ne 0 ]; then - _message "Error! Docker is not running." - return 1 - fi - - kind=$1 - shift - [[ $kind =~ (stopped|all) ]] && args=($args -a) - - lines=(${(f)"$(_call_program commands docker $docker_options ps $args)"}) - services=(${(f)"$(_call_program commands docker-compose 2>/dev/null $compose_options ps -q)"}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - lines=(${lines[2,-1]}) - - # Container ID - local line s name - local -a names - for line in $lines; do - if [[ ${services[@]} == *"${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}"* ]]; then - names=(${(ps:,:)${${line[${begin[NAMES]},-1]}%% *}}) - for name in $names; do - s="${${name%_*}#*_}:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" - s="$s, ${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}" - s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" - if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then - stopped=($stopped $s) - else - if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = *\(Paused\)* ]]; then - paused=($paused $s) - fi - running=($running $s) - fi - done - fi - done - - [[ $kind =~ (running|all) ]] && _describe -t services-running "running services" running "$@" && ret=0 - [[ $kind =~ (paused|all) ]] && _describe -t services-paused "paused services" paused "$@" && ret=0 - [[ $kind =~ (stopped|all) ]] && _describe -t services-stopped "stopped services" stopped "$@" && ret=0 - - return ret -} - -__docker-compose_pausedservices() { - [[ $PREFIX = -* ]] && return 1 - __docker-compose_get_services paused "$@" -} - -__docker-compose_stoppedservices() { - [[ $PREFIX = -* ]] && return 1 - __docker-compose_get_services stopped "$@" -} - -__docker-compose_runningservices() { - [[ $PREFIX = -* ]] && return 1 - __docker-compose_get_services running "$@" -} - -__docker-compose_services() { - [[ $PREFIX = -* ]] && return 1 - __docker-compose_get_services all "$@" -} - -__docker-compose_caching_policy() { - oldp=( "$1"(Nmh+1) ) # 1 hour - (( $#oldp )) -} - -__docker-compose_commands() { - local cache_policy - - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy __docker-compose_caching_policy - fi - - if ( [[ ${+_docker_compose_subcommands} -eq 0 ]] || _cache_invalid docker_compose_subcommands) \ - && ! _retrieve_cache docker_compose_subcommands; - then - local -a lines - lines=(${(f)"$(_call_program commands docker-compose 2>&1)"}) - _docker_compose_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) - (( $#_docker_compose_subcommands > 0 )) && _store_cache docker_compose_subcommands _docker_compose_subcommands - fi - _describe -t docker-compose-commands "docker-compose command" _docker_compose_subcommands -} - -__docker-compose_subcommand() { - local opts_help opts_force_recreate opts_no_recreate opts_no_build opts_remove_orphans opts_timeout opts_no_color opts_no_deps - - opts_help='(: -)--help[Print usage]' - opts_force_recreate="(--no-recreate)--force-recreate[Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.]" - opts_no_recreate="(--force-recreate)--no-recreate[If containers already exist, don't recreate them. Incompatible with --force-recreate.]" - opts_no_build="(--build)--no-build[Don't build an image, even if it's missing.]" - opts_remove_orphans="--remove-orphans[Remove containers for services not defined in the Compose file]" - opts_timeout=('(-t --timeout)'{-t,--timeout}"[Specify a shutdown timeout in seconds. (default: 10)]:seconds: ") - opts_no_color='--no-color[Produce monochrome output.]' - opts_no_deps="--no-deps[Don't start linked services.]" - - integer ret=1 - - case "$words[1]" in - (build) - _arguments \ - $opts_help \ - '--force-rm[Always remove intermediate containers.]' \ - '--no-cache[Do not use cache when building the image.]' \ - '--pull[Always attempt to pull a newer version of the image.]' \ - '*:services:__docker-compose_services_from_build' && ret=0 - ;; - (bundle) - _arguments \ - $opts_help \ - '(--output -o)'{--output,-o}'[Path to write the bundle file to. Defaults to ".dab".]:file:_files' && ret=0 - ;; - (config) - _arguments \ - $opts_help \ - '(--quiet -q)'{--quiet,-q}"[Only validate the configuration, don't print anything.]" \ - '--services[Print the service names, one per line.]' && ret=0 - ;; - (create) - _arguments \ - $opts_help \ - $opts_force_recreate \ - $opts_no_recreate \ - $opts_no_build \ - "(--no-build)--build[Build images before creating containers.]" \ - '*:services:__docker-compose_services_all' && ret=0 - ;; - (down) - _arguments \ - $opts_help \ - "--rmi[Remove images. Type must be one of: 'all': Remove all images used by any service. 'local': Remove only images that don't have a custom tag set by the \`image\` field.]:type:(all local)" \ - '(-v --volumes)'{-v,--volumes}"[Remove named volumes declared in the \`volumes\` section of the Compose file and anonymous volumes attached to containers.]" \ - $opts_remove_orphans && ret=0 - ;; - (events) - _arguments \ - $opts_help \ - '--json[Output events as a stream of json objects]' \ - '*:services:__docker-compose_services_all' && ret=0 - ;; - (exec) - _arguments \ - $opts_help \ - '-d[Detached mode: Run command in the background.]' \ - '--privileged[Give extended privileges to the process.]' \ - '--user=[Run the command as this user.]:username:_users' \ - '-T[Disable pseudo-tty allocation. By default `docker-compose exec` allocates a TTY.]' \ - '--index=[Index of the container if there are multiple instances of a service \[default: 1\]]:index: ' \ - '(-):running services:__docker-compose_runningservices' \ - '(-):command: _command_names -e' \ - '*::arguments: _normal' && ret=0 - ;; - (help) - _arguments ':subcommand:__docker-compose_commands' && ret=0 - ;; - (kill) - _arguments \ - $opts_help \ - '-s[SIGNAL to send to the container. Default signal is SIGKILL.]:signal:_signals' \ - '*:running services:__docker-compose_runningservices' && ret=0 - ;; - (logs) - _arguments \ - $opts_help \ - '(-f --follow)'{-f,--follow}'[Follow log output]' \ - $opts_no_color \ - '--tail=[Number of lines to show from the end of the logs for each container.]:number of lines: ' \ - '(-t --timestamps)'{-t,--timestamps}'[Show timestamps]' \ - '*:services:__docker-compose_services_all' && ret=0 - ;; - (pause) - _arguments \ - $opts_help \ - '*:running services:__docker-compose_runningservices' && ret=0 - ;; - (port) - _arguments \ - $opts_help \ - '--protocol=[tcp or udp \[default: tcp\]]:protocol:(tcp udp)' \ - '--index=[index of the container if there are multiple instances of a service \[default: 1\]]:index: ' \ - '1:running services:__docker-compose_runningservices' \ - '2:port:_ports' && ret=0 - ;; - (ps) - _arguments \ - $opts_help \ - '-q[Only display IDs]' \ - '*:services:__docker-compose_services_all' && ret=0 - ;; - (pull) - _arguments \ - $opts_help \ - '--ignore-pull-failures[Pull what it can and ignores images with pull failures.]' \ - '*:services:__docker-compose_services_from_image' && ret=0 - ;; - (push) - _arguments \ - $opts_help \ - '--ignore-push-failures[Push what it can and ignores images with push failures.]' \ - '*:services:__docker-compose_services' && ret=0 - ;; - (rm) - _arguments \ - $opts_help \ - '(-f --force)'{-f,--force}"[Don't ask to confirm removal]" \ - '-v[Remove any anonymous volumes attached to containers]' \ - '*:stopped services:__docker-compose_stoppedservices' && ret=0 - ;; - (run) - _arguments \ - $opts_help \ - '-d[Detached mode: Run container in the background, print new container name.]' \ - '*-e[KEY=VAL Set an environment variable (can be used multiple times)]:environment variable KEY=VAL: ' \ - '--entrypoint[Overwrite the entrypoint of the image.]:entry point: ' \ - '--name=[Assign a name to the container]:name: ' \ - $opts_no_deps \ - '(-p --publish)'{-p,--publish=}"[Publish a container's port(s) to the host]" \ - '--rm[Remove container after run. Ignored in detached mode.]' \ - "--service-ports[Run command with the service's ports enabled and mapped to the host.]" \ - '-T[Disable pseudo-tty allocation. By default `docker-compose run` allocates a TTY.]' \ - '(-u --user)'{-u,--user=}'[Run as specified username or uid]:username or uid:_users' \ - '(-w --workdir)'{-w,--workdir=}'[Working directory inside the container]:workdir: ' \ - '(-):services:__docker-compose_services' \ - '(-):command: _command_names -e' \ - '*::arguments: _normal' && ret=0 - ;; - (scale) - _arguments \ - $opts_help \ - $opts_timeout \ - '*:running services:__docker-compose_runningservices' && ret=0 - ;; - (start) - _arguments \ - $opts_help \ - '*:stopped services:__docker-compose_stoppedservices' && ret=0 - ;; - (stop|restart) - _arguments \ - $opts_help \ - $opts_timeout \ - '*:running services:__docker-compose_runningservices' && ret=0 - ;; - (unpause) - _arguments \ - $opts_help \ - '*:paused services:__docker-compose_pausedservices' && ret=0 - ;; - (up) - _arguments \ - $opts_help \ - '(--abort-on-container-exit)-d[Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit.]' \ - $opts_no_color \ - $opts_no_deps \ - $opts_force_recreate \ - $opts_no_recreate \ - $opts_no_build \ - "(--no-build)--build[Build images before starting containers.]" \ - "(-d)--abort-on-container-exit[Stops all containers if any container was stopped. Incompatible with -d.]" \ - '(-t --timeout)'{-t,--timeout}"[Use this timeout in seconds for container shutdown when attached or when containers are already running. (default: 10)]:seconds: " \ - $opts_remove_orphans \ - '*:services:__docker-compose_services_all' && ret=0 - ;; - (version) - _arguments \ - $opts_help \ - "--short[Shows only Compose's version number.]" && ret=0 - ;; - (*) - _message 'Unknown sub command' && ret=1 - ;; - esac - - return ret -} - -_docker-compose() { - # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. - # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. - if [[ $service != docker-compose ]]; then - _call_function - _$service - return - fi - - local curcontext="$curcontext" state line - integer ret=1 - typeset -A opt_args - - _arguments -C \ - '(- :)'{-h,--help}'[Get help]' \ - '(-f --file)'{-f,--file}'[Specify an alternate docker-compose file (default: docker-compose.yml)]:file:_files -g "*.yml"' \ - '(-p --project-name)'{-p,--project-name}'[Specify an alternate project name (default: directory name)]:project name:' \ - '--verbose[Show more output]' \ - '(- :)'{-v,--version}'[Print version and exit]' \ - '(-H --host)'{-H,--host}'[Daemon socket to connect to]:host:' \ - '--tls[Use TLS; implied by --tlsverify]' \ - '--tlscacert=[Trust certs signed only by this CA]:ca path:' \ - '--tlscert=[Path to TLS certificate file]:client cert path:' \ - '--tlskey=[Path to TLS key file]:tls key path:' \ - '--tlsverify[Use TLS and verify the remote]' \ - "--skip-hostname-check[Don't check the daemon's hostname against the name specified in the client certificate (for example if your docker host is an IP address)]" \ - '(-): :->command' \ - '(-)*:: :->option-or-argument' && ret=0 - - local -a relevant_compose_flags relevant_docker_flags compose_options docker_options - - relevant_compose_flags=( - "--file" "-f" - "--host" "-H" - "--project-name" "-p" - "--tls" - "--tlscacert" - "--tlscert" - "--tlskey" - "--tlsverify" - "--skip-hostname-check" - ) - - relevant_docker_flags=( - "--host" "-H" - "--tls" - "--tlscacert" - "--tlscert" - "--tlskey" - "--tlsverify" - ) - - for k in "${(@k)opt_args}"; do - if [[ -n "${relevant_docker_flags[(r)$k]}" ]]; then - docker_options+=$k - if [[ -n "$opt_args[$k]" ]]; then - docker_options+=$opt_args[$k] - fi - fi - if [[ -n "${relevant_compose_flags[(r)$k]}" ]]; then - compose_options+=$k - if [[ -n "$opt_args[$k]" ]]; then - compose_options+=$opt_args[$k] - fi - fi - done - - case $state in - (command) - __docker-compose_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-compose-$words[1]: - __docker-compose_subcommand && ret=0 - ;; - esac - - return ret -} - -_docker-compose "$@" - diff --git a/lib/local/_extract b/lib/local/_extract deleted file mode 100644 index 7839173..0000000 --- a/lib/local/_extract +++ /dev/null @@ -1,8 +0,0 @@ -#compdef extract -#autoload - -_arguments \ - '(-r --remove)'{-r,--remove}'[Remove archive.]' \ - "*::archive file:_files -g '(#i)*.(7z|Z|apk|bz2|deb|gz|ipsw|jar|lzma|rar|sublime-package|tar|tar.bz2|tar.gz|tar.xz|tar.zma|tbz|tbz2|tgz|tlz|txz|war|xpi|xz|zip)(-.)'" \ - && return 0 - diff --git a/lib/local/_lj b/lib/local/_lj deleted file mode 100644 index 20a9fe6..0000000 --- a/lib/local/_lj +++ /dev/null @@ -1,61 +0,0 @@ -#compdef lj - -### -# List of log levels -### -_levels=( - 'emergency' - 'alert' - 'critical' - 'error' - 'warning' - 'notice' - 'info' - 'debug' -) - -### -# Describe log levels -### -function _lumberjack_log_levels() { - _describe -t levels 'levels' _levels "$@" -} - -### -# Lumberjack completion -### -function _lumberjack() { - typeset -A opt_args - local context state line curcontext="$curcontext" - - # Set option arguments - _arguments -A \ - '(-h --help)'{-h,--help}'[show help text and exit]' \ - '(-v --version)'{-v,--version}'[show version information and exit]' \ - '(-f --file)'{-f,--file}'[set log file and exit]' \ - '(-l --level)'{-l,--level}'[set log level and exit]' \ - - # Set log level arguments - _arguments \ - '1: :_lumberjack_log_levels' \ - '*::arg:->args' - - # Complete option arguments - case "$state" in - args ) - case "$words[1]" in - --file|-f ) - _arguments \ - '1:file:_files' - ;; - --level|-l ) - _arguments \ - '1:level:_lumberjack_log_levels' - ;; - esac - ;; - esac -} - -_lumberjack "$@" - diff --git a/lib/local/_revolver b/lib/local/_revolver deleted file mode 100644 index 11e64e1..0000000 --- a/lib/local/_revolver +++ /dev/null @@ -1,34 +0,0 @@ -#compdef revolver - -_commands=( - 'start:start the spinner process' - 'update:update the message' - 'stop:stop the spinner process' - 'demo:display a demo of each style' -) - -### -# Complete revolver commands -### -function _revolver_commands() { - _describe -t commands 'commands' _commands "$@" -} - -### -# Revolver completion -### -function _revolver() { - typeset -A opt_args - local context state line curcontext="$curcontext" - - # Set option arguments - _arguments -A \ - '(-h --help)'{-h,--help}'[show help text and exit]' \ - '(-v --version)'{-v,--version}'[show version information and exit]' - - # Set log level arguments - _arguments \ - '1: :_revolver_commands' -} - -_revolver "$@" diff --git a/lib/local/_vagrant b/lib/local/_vagrant deleted file mode 100644 index a08a94a..0000000 --- a/lib/local/_vagrant +++ /dev/null @@ -1,131 +0,0 @@ -#compdef vagrant -#autoload - -# vagrant zsh completion - -local -a _1st_arguments -_1st_arguments=( - 'box:Box commands' - 'connect:Connects to a remotely shared Vagrant environment' - 'destroy:Destroys the vagrant environment' - 'docker-logs:Outputs the logs from the Docker container' - 'docker-run:Run a one-off command in the context of a container' - 'global-status:Reports the status of all active Vagrant environments on the system' - 'halt:Halts the currently running vagrant environment' - 'help:Shows the help for a subcommand' - 'init:[box_name] [box_url] Initializes current folder for Vagrant usage' - 'list-commands:Outputs all available Vagrant subcommands, even non-primary ones' - 'login:Authenticates against a Vagrant Cloud server to access protected boxes' - 'package:Packages a vagrant environment for distribution' - 'plugin:Plugin commands' - 'provision:Run the provisioner' - 'push:Deploys code in this environment to a configured destination' - 'rdp:Connects to machine via RDP' - 'reload:Reload the vagrant environment' - 'resume:Resumes a suspend vagrant environment' - 'rsync:Syncs rsync synced folders to remote machine' - 'rsync-auto:Syncs rsync synced folders automatically when files change' - 'share:Shares your Vagrant environment with anyone in the world' - 'snapshot:Manage snapshots with the guest machine' - 'ssh:SSH into the currently running environment' - 'ssh-config:Outputs .ssh/config valid syntax for connecting to this environment via ssh' - 'status:Shows the status of the current Vagrant environment' - 'suspend:Suspends the currently running vagrant environment' - 'snapshot:Used to manage snapshots with the guest machine' - 'up:Creates the vagrant environment' - 'version:Prints current and latest Vagrant version' - '--help:[TASK] Describe available tasks or one specific task' - '--version:Prints the Vagrant version information' -) - -local -a _box_arguments -_box_arguments=( - 'add:ADDRESS Adds a box to the system' - 'help:COMMAND List subcommands' - 'list:Lists all installed boxes' - 'outdated:Checks if a box has newer version' - 'remove:NAME Removes a box from the system' - 'repackage:NAME PROVIDER VERSION Repackages an installed box into a `.box` file' - 'update:Updates box to a newer version, if available' -) - -__task_list () -{ - local expl - declare -a tasks - - tasks=(box destroy halt init package provision reload resume ssh ssh_config status suspend up version) - - _wanted tasks expl 'help' compadd $tasks -} - -__box_list () -{ - _wanted application expl 'command' compadd $(command vagrant box list | sed -e 's/ /\\ /g') -} - -__vm_list () -{ - _wanted application expl 'command' compadd $(command grep Vagrantfile -oe '^[^#]*\.vm\.define *[:"]\([a-zA-Z0-9_-]\+\)' 2>/dev/null | awk '{print substr($2, 2)}') - _wanted application expl 'command' compadd $(command ls .vagrant/machines/ 2>/dev/null) -} - -__vagrant-box () -{ - local curcontext="$curcontext" state line - typeset -A opt_args - - _arguments -C \ - ':command:->command' \ - '*::options:->options' - - case $state in - (command) - _describe -t commands "gem subcommand" _box_arguments - return - ;; - - (options) - case $line[1] in - (repackage|remove) - _arguments ':feature:__box_list' - ;; - esac - ;; - esac -} - - - - -local expl -local -a boxes installed_boxes - -local curcontext="$curcontext" state line -typeset -A opt_args - -_arguments -C \ - ':command:->command' \ - '*::options:->options' - -case $state in - (command) - _describe -t commands "gem subcommand" _1st_arguments - return - ;; - - (options) - case $line[1] in - (help) - _arguments ':feature:__task_list' - ;; - - (box) - __vagrant-box - ;; - (up|provision|package|destroy|reload|ssh|ssh-config|halt|resume|status) - _arguments ':feature:__vm_list' - esac - ;; -esac - diff --git a/lib/local/prompt_z4rr3t_setup b/lib/local/prompt_z4rr3t_setup deleted file mode 100644 index 5296f43..0000000 --- a/lib/local/prompt_z4rr3t_setup +++ /dev/null @@ -1,135 +0,0 @@ -# z4rr3t -# by Garret Jennings -# https://github.com/inimicus/z4rr3t -# Based on Pure -# by Sindre Sorhus -# https://github.com/sindresorhus/pure -# MIT License - -# For my own and others sanity -# git: -# %b => current branch -# %a => current action (rebase/merge) -# prompt: -# %F => color dict -# %f => reset color -# %~ => current path -# %* => time -# %n => username -# %m => shortname host -# %(?..) => prompt conditional - %(condition.true.false) - - -# turns seconds into human readable time -# 165392 => 1d 21h 56m 32s -prompt_z4rr3t_human_time() { - echo -n " " - local tmp=$1 - local days=$(( tmp / 60 / 60 / 24 )) - local hours=$(( tmp / 60 / 60 % 24 )) - local minutes=$(( tmp / 60 % 60 )) - local seconds=$(( tmp % 60 )) - (( $days > 0 )) && echo -n "${days}d " - (( $hours > 0 )) && echo -n "${hours}h " - (( $minutes > 0 )) && echo -n "${minutes}m " - echo "${seconds}s" -} - -# fastest possible way to check if repo is dirty -prompt_z4rr3t_git_dirty() { - # check if we're in a git repo - [[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]] || return - # check if it's dirty - [[ "$Z4RR3T_GIT_UNTRACKED_DIRTY" == 0 ]] && local umode="-uno" || local umode="-unormal" - command test -n "$(git status --porcelain --ignore-submodules ${umode})" - - (($? == 0)) && echo '*' -} - -# displays the exec time of the last command if set threshold was exceeded -prompt_z4rr3t_cmd_exec_time() { - local stop=$EPOCHSECONDS - local start=${cmd_timestamp:-$stop} - integer elapsed=$stop-$start - (($elapsed > ${Z4RR3T_CMD_MAX_EXEC_TIME:=10})) && prompt_z4rr3t_human_time $elapsed -} - -prompt_z4rr3t_preexec() { - cmd_timestamp=$EPOCHSECONDS - - # shows the current dir and executed command in the title when a process is active - print -Pn "\e]0;" - echo -nE "$PWD:t: $2" - print -Pn "\a" -} - -# string length ignoring ansi escapes -prompt_z4rr3t_string_length() { - echo $(( ${#${(S%%)1//(\%([KF1]|)\{*\}|\%[Bbkf])}} )) -} - -prompt_z4rr3t_precmd() { - # shows the full path in the title - print -Pn '\e]0;%~\a' - - # git info - vcs_info - - local prompt_z4rr3t_preprompt="$prompt_z4rr3t_username%F{blue}%~%F{242}$vcs_info_msg_0_`prompt_z4rr3t_git_dirty`%f%F{yellow}`prompt_z4rr3t_cmd_exec_time`%f" - print -P $prompt_z4rr3t_preprompt - - # check async if there is anything to pull - (( ${Z4RR3T_GIT_PULL:-1} )) && { - # check if we're in a git repo - [[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]] && - # make sure working tree is not $HOME - [[ "$(command git rev-parse --show-toplevel)" != "$HOME" ]] && - # check check if there is anything to pull - command git fetch &>/dev/null && - # check if there is an upstream configured for this branch - command git rev-parse --abbrev-ref @'{u}' &>/dev/null && { - local arrows='' - (( $(command git rev-list --right-only --count HEAD...@'{u}' 2>/dev/null) > 0 )) && arrows='⇣' - (( $(command git rev-list --left-only --count HEAD...@'{u}' 2>/dev/null) > 0 )) && arrows+='⇡' - print -Pn "\e7\e[A\e[1G\e[`prompt_z4rr3t_string_length $prompt_z4rr3t_preprompt`C%F{cyan}${arrows}%f\e8" - } - } &! - - # reset value since `preexec` isn't always triggered - unset cmd_timestamp -} - - -prompt_z4rr3t_setup() { - # prevent percentage showing up - # if output doesn't end with a newline - export PROMPT_EOL_MARK='' - - # disable auth prompting on git 2.3+ - export GIT_TERMINAL_PROMPT=0 - - prompt_opts=(cr subst percent) - - zmodload zsh/datetime - autoload -Uz add-zsh-hook - autoload -Uz vcs_info - - add-zsh-hook precmd prompt_z4rr3t_precmd - add-zsh-hook preexec prompt_z4rr3t_preexec - - zstyle ':vcs_info:*' enable git - zstyle ':vcs_info:git*' formats ' %b' - zstyle ':vcs_info:git*' actionformats ' %b|%a' - - # show username@host if logged in through SSH - [[ "$SSH_CONNECTION" != '' ]] && prompt_z4rr3t_username='%F{yellow}%n%F{white}@%F{242}%m ' - - # show username@host if root, with username in white - [[ $UID -eq 0 ]] && prompt_z4rr3t_username='%F{white}%n%F{red}@%F{242}%m ' - - # prompt turns red if the previous command didn't exit with 0 - PROMPT="%(?.%F{magenta}.%F{red})${Z4RR3T_PROMPT_SYMBOL:-❯}%f " -} - -prompt_z4rr3t_setup "$@" - diff --git a/lib/ohmyzsh b/lib/ohmyzsh deleted file mode 160000 index 08beebd..0000000 --- a/lib/ohmyzsh +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 08beebd89f9eec956c126c732a287ec5a5a197a8