zsh: cleanup
This commit is contained in:
parent
9d322e30d0
commit
d5fc956748
2 changed files with 58 additions and 49 deletions
|
@ -74,14 +74,40 @@ function ntfy() {
|
|||
notify-send -u critical "$1 failed! " "exited with code: $?"
|
||||
}
|
||||
|
||||
function togglefg () {
|
||||
zle push-input -w
|
||||
BUFFER="fg"
|
||||
zle accept-line -w
|
||||
}
|
||||
zle -N togglefg
|
||||
|
||||
function whed() {
|
||||
script=$(which "$1")
|
||||
[ -e "$script" ] && $EDITOR $(which "$script")
|
||||
}
|
||||
|
||||
function workon_cwd() {
|
||||
local PROJECT_ROOT="${PWD}"
|
||||
|
||||
while [ "$PROJECT_ROOT" != "/" ] && [ ! -e "$PROJECT_ROOT/.venv" ] && [ ! -d "$PROJECT_ROOT/.git" ]; do
|
||||
local PROJECT_ROOT="$(dirname "$PROJECT_ROOT")"
|
||||
done
|
||||
|
||||
if [ -r "$PROJECT_ROOT/.venv" ]; then
|
||||
local ENV_NAME="$(cat $PROJECT_ROOT/.venv)"
|
||||
else
|
||||
local ENV_NAME="$(basename "$PROJECT_ROOT")"
|
||||
fi
|
||||
|
||||
[ -n "$CD_VIRTUAL_ENV" ] && [ "$ENV_NAME" != "$CD_VIRTUAL_ENV" ] && {
|
||||
[ -n "$VIRTUAL_ENV" ] && deactivate
|
||||
unset CD_VIRTUAL_ENV
|
||||
}
|
||||
|
||||
[ -n "$ENV_NAME" ] && [ ! "$(realpath "$VIRTUAL_ENV" 2>/dev/null)" = "$(realpath "$WORKON_HOME/$ENV_NAME")" ] && {
|
||||
if [ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]; then
|
||||
workon -n "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
|
||||
elif [ -e "$ENV_NAME/bin/activate" ]; then
|
||||
source "$ENV_NAME/bin/activate" && export CD_VIRTUAL_ENV="$ENV_NAME"
|
||||
else
|
||||
local ENV_NAME=""
|
||||
fi
|
||||
}
|
||||
|
||||
[ -z "$ENV_NAME" ] && [ -n "$CD_VIRTUAL_ENV" ] && [ -n "$VIRTUAL_ENV" ] && {
|
||||
deactivate && unset CD_VIRTUAL_ENV
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,39 @@
|
|||
|
||||
export PROMPT='%B%F{blue}%n%F{cyan}@%F{blue}%m %F{magenta}[%F{white}%3~%F{magenta}] %(?.%F{green}.%F{red})»%f%b '
|
||||
export RPROMPT='%(?..%F{red}%?) $(venv_prompt)'
|
||||
export HISTSIZE=10000000
|
||||
export SAVEHIST=10000000
|
||||
export HISTFILE="$XDG_DATA_HOME/zsh/history"
|
||||
export KEYTIMEOUT=1
|
||||
|
||||
[ ! -f $XDG_DATA_HOME/zsh/history ] && mkdir -p $XDG_DATA_HOME/zsh && touch $XDG_DATA_HOME/zsh/history
|
||||
|
||||
fpath=($XDG_CONFIG_HOME/zsh/completions $fpath)
|
||||
|
||||
setopt hist_ignore_all_dups hist_reduce_blanks hist_verify bang_hist interactive_comments autocd noflowcontrol longlistjobs nonomatch notify hash_list_all appendhistory sharehistory histignorespace prompt_subst
|
||||
setopt \
|
||||
AUTO_CD \
|
||||
BANG_HIST \
|
||||
HASH_LIST_ALL \
|
||||
HIST_IGNORE_DUPS \
|
||||
HIST_IGNORE_ALL_DUPS \
|
||||
HIST_FIND_NO_DUPS \
|
||||
HIST_SAVE_NO_DUPS \
|
||||
HIST_REDUCE_BLANKS \
|
||||
HIST_VERIFY \
|
||||
HIST_IGNORE_SPACE \
|
||||
INTERACTIVE_COMMENTS \
|
||||
LONG_LIST_JOBS \
|
||||
NO_FLOW_CONTROL \
|
||||
NO_NOMATCH \
|
||||
NOTIFY \
|
||||
PROMPT_SUBST \
|
||||
SHARE_HISTORY
|
||||
|
||||
autoload -Uz colors && colors
|
||||
autoload -Uz edit-command-line && zle -N edit-command-line
|
||||
autoload -Uz add-zsh-hook
|
||||
autoload -Uz compinit
|
||||
autoload -U add-zsh-hook
|
||||
|
||||
zstyle ':completion:*:git-checkout:*' sort false
|
||||
zstyle ':completion:*:descriptions' format '[%d]'
|
||||
|
@ -33,14 +55,9 @@ zle_highlight+=(paste:none)
|
|||
# Set the titlestring
|
||||
add-zsh-hook precmd write_title_wd
|
||||
add-zsh-hook preexec reset_beam
|
||||
|
||||
export HISTSIZE=10000000
|
||||
export SAVEHIST=10000000
|
||||
export HISTFILE="$XDG_DATA_HOME/zsh/history"
|
||||
export KEYTIMEOUT=1
|
||||
add-zsh-hook chpwd workon_cwd
|
||||
|
||||
# Virtualenvwrapper Setup
|
||||
|
||||
source "$(which virtualenvwrapper_lazy.sh)"
|
||||
type workon >/dev/null 2>&1
|
||||
[ -z "$WORKON_HOME" ] && {
|
||||
|
@ -48,39 +65,5 @@ type workon >/dev/null 2>&1
|
|||
return 1
|
||||
}
|
||||
|
||||
workon_cwd() {
|
||||
local PROJECT_ROOT="${PWD}"
|
||||
|
||||
while [ "$PROJECT_ROOT" != "/" ] && [ ! -e "$PROJECT_ROOT/.venv" ] && [ ! -d "$PROJECT_ROOT/.git" ]; do
|
||||
local PROJECT_ROOT="$(dirname "$PROJECT_ROOT")"
|
||||
done
|
||||
|
||||
if [ -r "$PROJECT_ROOT/.venv" ]; then
|
||||
local ENV_NAME="$(cat $PROJECT_ROOT/.venv)"
|
||||
else
|
||||
local ENV_NAME="$(basename "$PROJECT_ROOT")"
|
||||
fi
|
||||
|
||||
[ -n "$CD_VIRTUAL_ENV" ] && [ "$ENV_NAME" != "$CD_VIRTUAL_ENV" ] && {
|
||||
[ -n "$VIRTUAL_ENV" ] && deactivate
|
||||
unset CD_VIRTUAL_ENV
|
||||
}
|
||||
|
||||
[ -n "$ENV_NAME" ] && [ ! "$(realpath "$VIRTUAL_ENV" 2>/dev/null)" = "$(realpath "$WORKON_HOME/$ENV_NAME")" ] && {
|
||||
if [ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]; then
|
||||
workon -n "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
|
||||
elif [ -e "$ENV_NAME/bin/activate" ]; then
|
||||
source "$ENV_NAME/bin/activate" && export CD_VIRTUAL_ENV="$ENV_NAME"
|
||||
else
|
||||
local ENV_NAME=""
|
||||
fi
|
||||
}
|
||||
|
||||
[ -z "$ENV_NAME" ] && [ -n "$CD_VIRTUAL_ENV" ] && [ -n "$VIRTUAL_ENV" ] && {
|
||||
deactivate && unset CD_VIRTUAL_ENV
|
||||
}
|
||||
}
|
||||
|
||||
autoload -U add-zsh-hook
|
||||
add-zsh-hook chpwd workon_cwd
|
||||
# switch to virtualenv if terminal is started outside of home directory
|
||||
[ "$PWD" != ~ ] && workon_cwd
|
||||
|
|
Loading…
Add table
Reference in a new issue