Skip to content

Commit

Permalink
environment: Fix logic around url quoting in zsh >= 5.1
Browse files Browse the repository at this point in the history
Closes sorin-ionescu#1015, Fixes sorin-ionescu#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:
zimfw/zimfw@537f076#diff-30465d78a41f73dc0f6967d3f34d7964

Note that we need this workaround because we currently support back to
4.3.11.

I believe that originally came from here:
ohmyzsh/ohmyzsh#4473
  • Loading branch information
belak authored and Tai Allman committed Jun 11, 2018
1 parent ff9b901 commit fc5169e
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 125 deletions.
20 changes: 18 additions & 2 deletions modules/environment/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 39 additions & 3 deletions modules/prompt/functions/prompt_sorin_setup
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand All @@ -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"
}
Expand All @@ -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'
Expand Down Expand Up @@ -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]? '
}

Expand Down
8 changes: 4 additions & 4 deletions runcoms/zlogout
Original file line number Diff line number Diff line change
Expand Up @@ -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
139 changes: 23 additions & 116 deletions runcoms/zpreztorc
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,33 @@
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'

# 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 ''

Expand All @@ -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'
Expand All @@ -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'
7 changes: 7 additions & 0 deletions runcoms/zshenv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit fc5169e

Please sign in to comment.