From fc5169ed8bcab47f4dbc10cfd2e01d1447f79136 Mon Sep 17 00:00:00 2001 From: Kaleb Elwert Date: Mon, 6 Nov 2017 11:58:05 -0800 Subject: [PATCH] environment: Fix logic around url quoting in zsh >= 5.1 Closes #1015, Fixes #978 Thanks to @Eriner for pointing us in right direction. The code for this comes from zim. This is the last commit with the code we're using: https://github.com/Eriner/zim/commit/537f07660376f6fd0b8103ee993bfc132ddcee90#diff-30465d78a41f73dc0f6967d3f34d7964 Note that we need this workaround because we currently support back to 4.3.11. I believe that originally came from here: https://github.com/robbyrussell/oh-my-zsh/pull/4473 --- modules/environment/init.zsh | 20 ++- modules/prompt/functions/prompt_sorin_setup | 42 +++++- runcoms/zlogout | 8 +- runcoms/zpreztorc | 139 ++++---------------- runcoms/zshenv | 7 + runcoms/zshrc | 105 +++++++++++++++ 6 files changed, 196 insertions(+), 125 deletions(-) diff --git a/modules/environment/init.zsh b/modules/environment/init.zsh index 76655a6c7ea..e77a107cf52 100644 --- a/modules/environment/init.zsh +++ b/modules/environment/init.zsh @@ -9,8 +9,24 @@ # Smart URLs # -autoload -Uz url-quote-magic -zle -N self-insert url-quote-magic +# This logic comes from an old version of zim. Essentially, bracketed-paste was +# added as a requirement of url-quote-magic in 5.1, but in 5.1.1 bracketed +# paste had a regression. Additionally, 5.2 added bracketed-paste-url-magic +# which is generally better than url-quote-magic so we load that when possible. +autoload -Uz is-at-least +if [[ ${ZSH_VERSION} != 5.1.1 ]]; then + if is-at-least 5.2; then + autoload -Uz bracketed-paste-url-magic + zle -N bracketed-paste bracketed-paste-url-magic + else + if is-at-least 5.1; then + autoload -Uz bracketed-paste-magic + zle -N bracketed-paste bracketed-paste-magic + fi + fi + autoload -Uz url-quote-magic + zle -N self-insert url-quote-magic +fi # # General diff --git a/modules/prompt/functions/prompt_sorin_setup b/modules/prompt/functions/prompt_sorin_setup index c2258867cf0..eff2fff556f 100644 --- a/modules/prompt/functions/prompt_sorin_setup +++ b/modules/prompt/functions/prompt_sorin_setup @@ -32,6 +32,38 @@ # Load dependencies. pmodload 'helper' +# turns seconds into human readable time +# 165392 => 1d 21h 56m 32s +# https://github.com/sindresorhus/pretty-time-zsh +function prompt_sorin_human_time_to_var { + local human=" " total_seconds=$1 var=$2 + local days=$(( total_seconds / 60 / 60 / 24 )) + local hours=$(( total_seconds / 60 / 60 % 24 )) + local minutes=$(( total_seconds / 60 % 60 )) + local seconds=$(( total_seconds % 60 )) + (( days > 0 )) && human+="${days}d " + (( hours > 0 )) && human+="${hours}h " + (( minutes > 0 )) && human+="${minutes}m " + human+="${seconds}s" + + # store human readable time in variable as specified by caller + typeset -g "${var}"="${human}" +} + +# stores (into prompt_sorin_cmd_exec_time) the exec time of the last command if set threshold was exceeded +function prompt_sorin_check_cmd_exec_time { + integer elapsed + (( elapsed = EPOCHSECONDS - ${prompt_sorin_cmd_timestamp:-$EPOCHSECONDS} )) + prompt_sorin_cmd_exec_time= + (( elapsed > ${PURE_CMD_MAX_EXEC_TIME:=5} )) && { + prompt_sorin_human_time_to_var $elapsed "prompt_sorin_cmd_exec_time" + } +} + +function prompt_sorin_preexec { + prompt_sorin_cmd_timestamp=$EPOCHSECONDS +} + function prompt_sorin_git_info { # We can safely split on ':' because it isn't allowed in ref names. IFS=':' read _git_target _git_post_target <<<"$3" @@ -65,6 +97,9 @@ function prompt_sorin_precmd { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS + # check exec time and store it in a variable + prompt_sorin_check_cmd_exec_time + # Format PWD. _prompt_sorin_pwd=$(prompt-pwd) @@ -81,12 +116,12 @@ function prompt_sorin_precmd { fi fi - + # Run python info (this should be fast and not require any async) if (( $+functions[python-info] )); then python-info fi - + # Compute slow commands in the background. async_job async_sorin_git prompt_sorin_async_git "$PWD" } @@ -104,6 +139,7 @@ function prompt_sorin_setup { # Add hook for calling git-info before each command. add-zsh-hook precmd prompt_sorin_precmd + add-zsh-hook preexec prompt_sorin_preexec # Set editor-info parameters. zstyle ':prezto:module:editor:info:completing' format '%B%F{7}...%f%b' @@ -150,7 +186,7 @@ function prompt_sorin_setup { PROMPT='${SSH_TTY:+"%F{9}%n%f%F{7}@%f%F{3}%m%f "}%F{4}${_prompt_sorin_pwd}%(!. %B%F{1}#%f%b.)${editor_info[keymap]} ' RPROMPT='$python_info[virtualenv]${editor_info[overwrite]}%(?:: %F{1}' RPROMPT+=${show_return} - RPROMPT+='%f)${VIM:+" %B%F{6}V%f%b"}${_prompt_sorin_git}' + RPROMPT+='%f)${VIM:+" %B%F{6}V%f%b"}${_prompt_sorin_git}%F{yellow}$prompt_sorin_cmd_exec_time%f' SPROMPT='zsh: correct %F{1}%R%f to %F{2}%r%f [nyae]? ' } diff --git a/runcoms/zlogout b/runcoms/zlogout index 7c27e88581c..0e5f53008b4 100644 --- a/runcoms/zlogout +++ b/runcoms/zlogout @@ -6,8 +6,8 @@ # # Print the message. -cat <<-EOF +# cat <<-EOF -Thank you. Come again! - -- Dr. Apu Nahasapeemapetilon -EOF +# Thank you. Come again! +# -- Dr. Apu Nahasapeemapetilon +# EOF diff --git a/runcoms/zpreztorc b/runcoms/zpreztorc index cd92317fd11..f64ec7952b2 100644 --- a/runcoms/zpreztorc +++ b/runcoms/zpreztorc @@ -16,7 +16,7 @@ zstyle ':prezto:*:*' color 'yes' # Set the Zsh modules to load (man zshmodules). -# zstyle ':prezto:load' zmodule 'attr' 'stat' +zstyle ':prezto:load' zmodule 'files' # 'attr' 'stat' # Set the Zsh functions to load (man zshcontrib). # zstyle ':prezto:load' zfunction 'zargs' 'zmv' @@ -24,20 +24,25 @@ zstyle ':prezto:*:*' color 'yes' # Set the Prezto modules to load (browse modules). # The order matters. zstyle ':prezto:load' pmodule \ - 'environment' \ - 'terminal' \ + 'command-not-found' \ + 'directory' \ 'editor' \ + 'environment' \ + 'git' \ 'history' \ - 'directory' \ + 'terminal' \ 'spectrum' \ + 'ssh' \ + 'syntax-highlighting' \ 'utility' \ 'completion' \ + 'history-substring-search' \ + 'autosuggestions' \ 'prompt' # # Autosuggestions # - # Set the query found color. # zstyle ':prezto:module:autosuggestions:color' found '' @@ -52,139 +57,61 @@ zstyle ':prezto:load' pmodule \ # # Editor # - # Set the key mapping style to 'emacs' or 'vi'. zstyle ':prezto:module:editor' key-bindings 'emacs' # Auto convert .... to ../.. -# zstyle ':prezto:module:editor' dot-expansion 'yes' +zstyle ':prezto:module:editor' dot-expansion 'yes' # Allow the zsh prompt context to be shown. -#zstyle ':prezto:module:editor' ps-context 'yes' +# zstyle ':prezto:module:editor' ps-context 'yes' # # Git # - -# Ignore submodules when they are 'dirty', 'untracked', 'all', or 'none'. -# zstyle ':prezto:module:git:status:ignore' submodules 'all' - -# -# GNU Utility -# - -# Set the command prefix on non-GNU systems. -# zstyle ':prezto:module:gnu-utility' prefix 'g' - -# -# History Substring Search -# - -# Set the query found color. -# zstyle ':prezto:module:history-substring-search:color' found '' - -# Set the query not found color. -# zstyle ':prezto:module:history-substring-search:color' not-found '' - -# Set the search globbing flags. -# zstyle ':prezto:module:history-substring-search' globbing-flags '' - -# -# OS X -# - -# Set the keyword used by `mand` to open man pages in Dash.app -# zstyle ':prezto:module:osx:man' dash-keyword 'manpages' - -# -# Pacman -# - -# Set the Pacman frontend. -# zstyle ':prezto:module:pacman' frontend 'yaourt' +zstyle ':prezto:module:git:alias' skip 'yes' # # Prompt # - -# Set the prompt theme to load. -# Setting it to 'random' loads a random theme. -# Auto set to 'off' on dumb terminals. zstyle ':prezto:module:prompt' theme 'sorin' # Set the working directory prompt display length. # By default, it is set to 'short'. Set it to 'long' (without '~' expansion) # for longer or 'full' (with '~' expansion) for even longer prompt display. -# zstyle ':prezto:module:prompt' pwd-length 'short' +zstyle ':prezto:module:prompt' pwd-length 'short' # Set the prompt to display the return code along with an indicator for non-zero # return codes. This is not supported by all prompts. -# zstyle ':prezto:module:prompt' show-return-val 'yes' - -# -# Ruby -# - -# Auto switch the Ruby version on directory change. -# zstyle ':prezto:module:ruby:chruby' auto-switch 'yes' - -# -# Python -# - -# Auto switch the Python virtualenv on directory change. -# zstyle ':prezto:module:python:virtualenv' auto-switch 'yes' - -# Automatically initialize virtualenvwrapper if pre-requisites are met. -# zstyle ':prezto:module:python:virtualenv' initialize 'yes' - -# -# Screen -# - -# Auto start a session when Zsh is launched in a local terminal. -# zstyle ':prezto:module:screen:auto-start' local 'yes' - -# Auto start a session when Zsh is launched in a SSH connection. -# zstyle ':prezto:module:screen:auto-start' remote 'yes' +zstyle ':prezto:module:prompt' show-return-val 'yes' # # SSH # - # Set the SSH identities to load into the agent. -# zstyle ':prezto:module:ssh:load' identities 'id_rsa' 'id_rsa2' 'id_github' +zstyle ':prezto:module:ssh:load' identities 'id_rsa' # 'id_rsa2' 'id_github' # # Syntax Highlighting # +# Set syntax highlighters. By default, only the main highlighter is enabled. +zstyle ':prezto:module:syntax-highlighting' highlighters 'main' 'brackets' 'pattern' 'line' 'cursor' 'root' + +# Set syntax pattern styles. +zstyle ':prezto:module:syntax-highlighting' pattern 'rm*-rf*' 'fg=white,bold,bg=red' -# Set syntax highlighters. -# By default, only the main highlighter is enabled. -# zstyle ':prezto:module:syntax-highlighting' highlighters \ -# 'main' \ -# 'brackets' \ -# 'pattern' \ -# 'line' \ -# 'cursor' \ -# 'root' -# # Set syntax highlighting styles. # zstyle ':prezto:module:syntax-highlighting' styles \ # 'builtin' 'bg=blue' \ # 'command' 'bg=blue' \ # 'function' 'bg=blue' -# -# Set syntax pattern styles. -# zstyle ':prezto:module:syntax-highlighting' pattern \ -# 'rm*-rf*' 'fg=white,bold,bg=red' # # Terminal # # Auto set the tab and window titles. -# zstyle ':prezto:module:terminal' auto-title 'yes' +zstyle ':prezto:module:terminal' auto-title 'always' # Set the window title format. # zstyle ':prezto:module:terminal:window-title' format '%n@%m: %s' @@ -195,27 +122,7 @@ zstyle ':prezto:module:prompt' theme 'sorin' # Set the terminal multiplexer title format. # zstyle ':prezto:module:terminal:multiplexer-title' format '%s' -# -# Tmux -# - -# Auto start a session when Zsh is launched in a local terminal. -# zstyle ':prezto:module:tmux:auto-start' local 'yes' - -# Auto start a session when Zsh is launched in a SSH connection. -# zstyle ':prezto:module:tmux:auto-start' remote 'yes' - -# Integrate with iTerm2. -# zstyle ':prezto:module:tmux:iterm' integrate 'yes' - -# Set the default session name: -# zstyle ':prezto:module:tmux:session' name 'YOUR DEFAULT SESSION NAME' - # # Utility # - -# Enabled safe options. This aliases cp, ln, mv and rm so that they prompt -# before deleting or overwriting files. Set to 'no' to disable this safer -# behavior. -# zstyle ':prezto:module:utility' safe-ops 'yes' +zstyle ':prezto:module:utility' safe-ops 'no' diff --git a/runcoms/zshenv b/runcoms/zshenv index 2dbf12a8bf7..7f0af074c95 100644 --- a/runcoms/zshenv +++ b/runcoms/zshenv @@ -9,3 +9,10 @@ if [[ ( "$SHLVL" -eq 1 && ! -o LOGIN ) && -s "${ZDOTDIR:-$HOME}/.zprofile" ]]; then source "${ZDOTDIR:-$HOME}/.zprofile" fi + +export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' +path=($HOME/bin $path) + +if [[ -s "${ZDOTDIR:-$HOME/.config}/vertica.zshenv" ]]; then + source "${ZDOTDIR:-$HOME/.config}/vertica.zshenv" +fi diff --git a/runcoms/zshrc b/runcoms/zshrc index 039b882d880..853db749f22 100644 --- a/runcoms/zshrc +++ b/runcoms/zshrc @@ -10,4 +10,109 @@ if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" fi +if [[ -s "${ZDOTDIR:-$HOME/.config}/vertica.zshrc" ]]; then + source "${ZDOTDIR:-$HOME/.config}/vertica.zshrc" +fi + +setopt menucomplete +zstyle ':completion:*' menu select=2 + # Customize to your needs... +alias alig='alias | grep ' +alias zlogin='nano ~/.zlogin' +alias zlogout='nano ~/.zlogout' +alias zpreztorc='nano ~/.zpreztorc' +alias zprofile='nano ~/.zprofile' +alias zshenv='nano ~/.zshenv && source ~/.zshenv' +alias zshrc='nano ~/.zshrc && source ~/.zshrc' + +alias rsync='noglob noremoteglob rsync -ac --progress --no-l --exclude-from ~/.config/gitignore_global' + +# Git aliases are organized by subcommand each one having a unique prefix (ga, gb, gc, gco, etc) +alias alias g='git' + +alias ga='git add' +alias gaa='git add --all' + +alias gb='noglob git branch' +alias gba='noglob git branch -a' +alias gbd='noglob git branch -d' +alias gbD='noglob git branch -D' +alias gbl='noglob git branch --list' +alias gbla='noglob git branch -a --list' +alias gbv='git branch -vv' +alias gbsu='git branch --track origin $(git-branch-current)' + +alias gc='git commit -v' +alias gca='git commit -v -a' +alias gcm='git commit -v -m' +alias gcam='git commit -a -m' +alias gc!='git commit -v --amend' +alias gca!='git commit -v -a --amend' +alias gcn!='git commit -v --no-edit --amend' +alias gcan!='git commit -v -a --no-edit --amend' + +alias gco='git checkout' +alias gcob='git checkout -b' +alias gcom='git checkout master' + +alias gcp='git cherry-pick' +alias gcpa='git cherry-pick --abort' +alias gcpc='git cherry-pick --continue' + +alias gd='git diff' +alias gdc='git diff --cached' + +alias gk='\gitk --all --branches' +compdef _git gk='gitk' +alias gke='\gitk --all $(git log -g --pretty=%h)' +compdef _git gke='gitk' + +alias gl='git log --stat' +alias glg='git log --graph --decorate --all' +alias glo='git log --oneline --decorate' +alias glol="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" +alias glola="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all" +alias glog='git log --oneline --decorate --graph' +alias gloga='git log --oneline --decorate --graph --all' + +alias gm='git merge' +alias gma='git merge --abort' + +alias gmt='git mergetool --no-prompt' + +alias gp='git push -v' +alias gpsu='git push --set-upstream origin $(git-branch-current)' + +alias gpl='git pull --ff-only' +alias gplr='git pull --rebase' +alias gplrv='git pull --rebase -v' + +alias grb='git rebase' +alias grba='git rebase --abort' +alias grbc='git rebase --continue' +alias grbi='git rebase -i' +alias grbm='git rebase origin/master' +alias grbim='git rebase -i origin/master' + +alias grm='git rm' + +alias grh='git reset HEAD' +alias grhh='git reset HEAD --hard' +alias grh1='git reset HEAD~1' +alias grh1h='git reset HEAD~1 --hard' + +alias gs='git status' + +alias gst='git stash save' +alias gsta='git stash apply' +alias gstc='git stash clear' +alias gstd='git stash drop' +alias gstl='git stash list' +alias gstp='git stash pop' +alias gsts='git stash show --text' + +alias gclone='git clone --recursive' +alias gclean='git clean -fd' +alias gpristine='git reset --hard && git clean -dfx' +alias ggui='git gui &'