diff options
-rw-r--r-- | lib/prompt_info_functions.zsh | 1 | ||||
-rw-r--r-- | plugins/emotty/emotty.plugin.zsh | 2 | ||||
-rw-r--r-- | plugins/fossil/fossil.plugin.zsh | 4 | ||||
-rw-r--r-- | plugins/fzf/fzf.plugin.zsh | 20 | ||||
-rw-r--r-- | plugins/git/README.md | 1 | ||||
-rw-r--r-- | plugins/git/git.plugin.zsh | 1 | ||||
-rw-r--r-- | plugins/ssh-agent/README.md | 24 | ||||
-rw-r--r-- | plugins/ssh-agent/ssh-agent.plugin.zsh | 4 | ||||
-rw-r--r-- | plugins/terraform/terraform.plugin.zsh | 4 | ||||
-rw-r--r-- | plugins/vi-mode/vi-mode.plugin.zsh | 4 | ||||
-rw-r--r-- | themes/gentoo.zsh-theme | 30 | ||||
-rwxr-xr-x | tools/install.sh | 27 | ||||
-rw-r--r-- | tools/uninstall.sh | 16 |
13 files changed, 101 insertions, 37 deletions
diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh index 5069c4b21..48f033da6 100644 --- a/lib/prompt_info_functions.zsh +++ b/lib/prompt_info_functions.zsh @@ -18,6 +18,7 @@ function chruby_prompt_info \ vi_mode_prompt_info \ virtualenv_prompt_info \ jenv_prompt_info \ + tf_prompt_info \ { return 1 } diff --git a/plugins/emotty/emotty.plugin.zsh b/plugins/emotty/emotty.plugin.zsh index e288b5cfb..4511275d6 100644 --- a/plugins/emotty/emotty.plugin.zsh +++ b/plugins/emotty/emotty.plugin.zsh @@ -29,7 +29,7 @@ function emotty() { # Parse tty number via prompt expansion. %l equals: # - N if tty = /dev/ttyN # - pts/N if tty = /dev/pts/N - local tty = ${${(%):-%l}##pts/} + local tty=${${(%):-%l}##pts/} # Normalize it to an emotty set index (( tty = (tty % ${#${=emotty}}) + 1 )) diff --git a/plugins/fossil/fossil.plugin.zsh b/plugins/fossil/fossil.plugin.zsh index 1ae166e62..25a8d121d 100644 --- a/plugins/fossil/fossil.plugin.zsh +++ b/plugins/fossil/fossil.plugin.zsh @@ -73,9 +73,9 @@ function _fossil_prompt () { local is_prompt=`echo $PROMPT | grep git` if [ "$is_prompt" = "" ]; then - export RPROMPT="$_rprompt"'$(fossil_prompt_info)' + RPROMPT="$_rprompt"'$(fossil_prompt_info)' else - export PROMPT="$_prompt"'$(fossil_prompt_info) ' + PROMPT="$_prompt"'$(fossil_prompt_info) ' fi _FOSSIL_PROMPT="1" diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index 524089983..69ec1d411 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -64,11 +64,21 @@ function setup_using_debian_package() { # NOTE: There is no need to configure PATH for debian package, all binaries # are installed to /usr/bin by default - # Determine completion file path: first bullseye/sid, then buster/stretch - local completions="/usr/share/doc/fzf/examples/completion.zsh" - [[ -f "$completions" ]] || completions="/usr/share/zsh/vendor-completions/_fzf" - - local key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh" + local completions key_bindings + + case $PREFIX in + *com.termux*) + # Support Termux package + completions="${PREFIX}/share/fzf/completion.zsh" + key_bindings="${PREFIX}/share/fzf/key-bindings.zsh" + ;; + *) + # Determine completion file path: first bullseye/sid, then buster/stretch + completions="/usr/share/doc/fzf/examples/completion.zsh" + [[ -f "$completions" ]] || completions="/usr/share/zsh/vendor-completions/_fzf" + key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh" + ;; + esac # Auto-completion if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then diff --git a/plugins/git/README.md b/plugins/git/README.md index 029386267..6ad19543e 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -124,6 +124,7 @@ plugins=(... git) | grbd | git rebase develop | | grbi | git rebase -i | | grbm | git rebase $(git_main_branch) | +| grbo | git rebase --onto | | grbs | git rebase --skip | | grev | git revert | | grh | git reset | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 2f97dbc92..8167980fa 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -224,6 +224,7 @@ alias grbc='git rebase --continue' alias grbd='git rebase develop' alias grbi='git rebase -i' alias grbm='git rebase $(git_main_branch)' +alias grbo='git rebase --onto' alias grbs='git rebase --skip' alias grev='git revert' alias grh='git reset' diff --git a/plugins/ssh-agent/README.md b/plugins/ssh-agent/README.md index 0b96d9bb5..8765a9c7e 100644 --- a/plugins/ssh-agent/README.md +++ b/plugins/ssh-agent/README.md @@ -9,7 +9,7 @@ To enable it, add `ssh-agent` to your plugins: plugins=(... ssh-agent) ``` -## Instructions +## Settings **IMPORTANT: put these settings _before_ the line that sources oh-my-zsh** @@ -19,12 +19,16 @@ To enable **agent forwarding support** add the following to your zshrc file: zstyle :omz:plugins:ssh-agent agent-forwarding on ``` +---- + To **load multiple identities** use the `identities` style, For example: ```zsh zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github ``` +---- + To **set the maximum lifetime of the identities**, use the `lifetime` style. The lifetime may be specified in seconds or as described in sshd_config(5) (see _TIME FORMATS_). If left unspecified, the default lifetime is forever. @@ -33,6 +37,24 @@ The lifetime may be specified in seconds or as described in sshd_config(5) zstyle :omz:plugins:ssh-agent lifetime 4h ``` +---- + +To **pass arguments to the `ssh-add` command** that adds the identities on startup, +use the `ssh-add-args` setting. You can pass multiple arguments separated by spaces: + +```zsh +zstyle :omz:plugins:ssh-agent ssh-add-args -K -c -a /run/user/1000/ssh-auth +``` + +These will then be passed the the `ssh-add` call as if written directly. The example +above will turn into: + +```zsh +ssh-add -K -c -a /run/user/1000/ssh-auth <identities> +``` + +For valid `ssh-add` arguments run `ssh-add --help` or `man ssh-add`. + ## Credits Based on code from Joseph M. Reagle: https://www.cygwin.com/ml/cygwin/2001-06/msg00537.html diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index 6ab041c21..430647135 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -48,7 +48,9 @@ function _add_identities() { fi done - [[ -n "$not_loaded" ]] && ssh-add ${^not_loaded} + local args + zstyle -a :omz:plugins:ssh-agent ssh-add-args args + [[ -n "$not_loaded" ]] && ssh-add "${args[@]}" ${^not_loaded} } # Get the filename to store/lookup the environment from diff --git a/plugins/terraform/terraform.plugin.zsh b/plugins/terraform/terraform.plugin.zsh index 2c42d394d..997241c9a 100644 --- a/plugins/terraform/terraform.plugin.zsh +++ b/plugins/terraform/terraform.plugin.zsh @@ -2,8 +2,8 @@ function tf_prompt_info() { # dont show 'default' workspace in home dir [[ "$PWD" == ~ ]] && return # check if in terraform dir - if [ -d .terraform ]; then - workspace=$(terraform workspace show 2> /dev/null) || return + if [[ -d .terraform && -r .terraform/environment ]]; then + workspace=$(cat .terraform/environment) || return echo "[${workspace}]" fi } diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 7f14961ad..dd4afdd8b 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -50,13 +50,17 @@ zle -N zle-keymap-select # These "echoti" statements were originally set in lib/key-bindings.zsh # Not sure the best way to extend without overriding. function zle-line-init() { + local prev_vi_keymap + prev_vi_keymap="${VI_KEYMAP:-}" typeset -g VI_KEYMAP=main + [[ "$prev_vi_keymap" != 'main' ]] && [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]] && zle reset-prompt (( ! ${+terminfo[smkx]} )) || echoti smkx _vi-mode-set-cursor-shape-for-keymap "${VI_KEYMAP}" } zle -N zle-line-init function zle-line-finish() { + typeset -g VI_KEYMAP=main (( ! ${+terminfo[rmkx]} )) || echoti rmkx _vi-mode-set-cursor-shape-for-keymap default } diff --git a/themes/gentoo.zsh-theme b/themes/gentoo.zsh-theme index 5f2427c7a..ae3274022 100644 --- a/themes/gentoo.zsh-theme +++ b/themes/gentoo.zsh-theme @@ -1,8 +1,28 @@ -function prompt_char { - if [ $UID -eq 0 ]; then echo "#"; else echo $; fi +autoload -Uz colors && colors + +autoload -Uz vcs_info +zstyle ':vcs_info:*' check-for-changes true +zstyle ':vcs_info:*' unstagedstr '%F{red}*' # display this when there are unstaged changes +zstyle ':vcs_info:*' stagedstr '%F{yellow}+' # display this when there are staged changes +zstyle ':vcs_info:*' actionformats '%F{5}(%F{2}%b%F{3}|%F{1}%a%c%u%m%F{5})%f ' +zstyle ':vcs_info:*' formats '%F{5}(%F{2}%b%c%u%m%F{5})%f ' +zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r' +zstyle ':vcs_info:*' enable git cvs svn +zstyle ':vcs_info:git*+set-message:*' hooks untracked-git + ++vi-untracked-git() { + if command git status --porcelain 2>/dev/null | command grep -q '??'; then + hook_com[misc]='%F{red}?' + else + hook_com[misc]='' + fi +} + +gentoo_precmd() { + vcs_info } -PROMPT='%(!.%{$fg_bold[red]%}.%{$fg_bold[green]%}%n@)%m %{$fg_bold[blue]%}%(!.%1~.%~) $(git_prompt_info)$(prompt_char)%{$reset_color%} ' +autoload -U add-zsh-hook +add-zsh-hook precmd gentoo_precmd -ZSH_THEME_GIT_PROMPT_PREFIX="(" -ZSH_THEME_GIT_PROMPT_SUFFIX=") " +PROMPT='%(!.%B%F{red}.%B%F{green}%n@)%m %F{blue}%(!.%1~.%~) ${vcs_info_msg_0_}%(!.#.$)%{$reset_color%} ' diff --git a/tools/install.sh b/tools/install.sh index 953c68baf..d4ecb7afe 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -57,15 +57,16 @@ command_exists() { } fmt_error() { - echo ${RED}"Error: $@"${RESET} >&2 + printf '%sError: %s%s\n' "$BOLD$RED" "$*" "$RESET" >&2 } fmt_underline() { - echo "$(printf '\033[4m')$@$(printf '\033[24m')" + printf '\033[4m%s\033[24m\n' "$*" } fmt_code() { - echo "\`$(printf '\033[38;5;247m')$@${RESET}\`" + # shellcheck disable=SC2016 # backtic in single-quote + printf '`\033[38;5;247m%s%s`\n' "$*" "$RESET" } setup_color() { @@ -102,7 +103,8 @@ setup_ohmyzsh() { exit 1 } - if [ "$OSTYPE" = cygwin ] && git --version | grep -q msysgit; then + ostype=$(uname) + if [ -z "${ostype%CYGWIN*}" ] && git --version | grep -q msysgit; then fmt_error "Windows/MSYS Git is not supported on Cygwin" fmt_error "Make sure the Cygwin git package is installed and is first on the \$PATH" exit 1 @@ -130,7 +132,7 @@ setup_zshrc() { OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then # Skip this if the user doesn't want to replace an existing .zshrc - if [ $KEEP_ZSHRC = yes ]; then + if [ "$KEEP_ZSHRC" = yes ]; then echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}" return fi @@ -162,7 +164,7 @@ export ZSH=\"$ZSH\" setup_shell() { # Skip setup if the user wants or stdin is closed (not running interactively). - if [ $CHSH = no ]; then + if [ "$CHSH" = no ]; then return fi @@ -183,8 +185,9 @@ EOF echo "${BLUE}Time to change your default shell to zsh:${RESET}" # Prompt for user choice on changing the default login shell - printf "${YELLOW}Do you want to change your default shell to zsh? [Y/n]${RESET} " - read opt + printf '%sDo you want to change your default shell to zsh? [Y/n]%s ' \ + "$YELLOW" "$RESET" + read -r opt case $opt in y*|Y*|"") echo "Changing the shell..." ;; n*|N*) echo "Shell change skipped."; return ;; @@ -211,7 +214,7 @@ EOF # Get the path to the right zsh binary # 1. Use the most preceding one based on $PATH, then check that it's in the shells file # 2. If that fails, get a zsh path from the shells file, then check it actually exists - if ! zsh=$(which zsh) || ! grep -qx "$zsh" "$shells_file"; then + if ! zsh=$(command -v zsh) || ! grep -qx "$zsh" "$shells_file"; then if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then fmt_error "no zsh binary found or not present in '$shells_file'" fmt_error "change your default shell manually." @@ -222,7 +225,7 @@ EOF # We're going to change the default shell, so back up the current one if [ -n "$SHELL" ]; then - echo $SHELL > ~/.shell.pre-oh-my-zsh + echo "$SHELL" > ~/.shell.pre-oh-my-zsh else grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh fi @@ -288,7 +291,7 @@ EOF setup_zshrc setup_shell - printf "$GREEN" + printf %s "$GREEN" cat <<'EOF' __ __ ____ / /_ ____ ___ __ __ ____ _____/ /_ @@ -307,7 +310,7 @@ Before you scream Oh My Zsh! please look over the ~/.zshrc file to select plugin • Get stickers, shirts, coffee mugs and other swag: $(fmt_underline https://shop.planetargon.com/collections/oh-my-zsh) EOF - printf "$RESET" + printf %s "$RESET" if [ $RUNZSH = no ]; then echo "${YELLOW}Run zsh to try it out.${RESET}" diff --git a/tools/uninstall.sh b/tools/uninstall.sh index b327a0163..6a0e7b4c7 100644 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -9,20 +9,20 @@ if [ -d ~/.oh-my-zsh ]; then rm -rf ~/.oh-my-zsh fi +if [ -e ~/.zshrc ]; then + ZSHRC_SAVE=~/.zshrc.omz-uninstalled-$(date +%Y-%m-%d_%H-%M-%S) + echo "Found ~/.zshrc -- Renaming to ${ZSHRC_SAVE}" + mv ~/.zshrc "${ZSHRC_SAVE}" +fi + echo "Looking for original zsh config..." ZSHRC_ORIG=~/.zshrc.pre-oh-my-zsh if [ -e "$ZSHRC_ORIG" ]; then echo "Found $ZSHRC_ORIG -- Restoring to ~/.zshrc" - - if [ -e ~/.zshrc ]; then - ZSHRC_SAVE=~/.zshrc.omz-uninstalled-$(date +%Y-%m-%d_%H-%M-%S) - echo "Found ~/.zshrc -- Renaming to ${ZSHRC_SAVE}" - mv ~/.zshrc "${ZSHRC_SAVE}" - fi - mv "$ZSHRC_ORIG" ~/.zshrc - echo "Your original zsh config was restored." +else + echo "No original zsh config found" fi if hash chsh >/dev/null 2>&1 && [ -f ~/.shell.pre-oh-my-zsh ]; then |