summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cli.zsh47
-rw-r--r--lib/correction.zsh1
-rw-r--r--lib/git.zsh3
-rw-r--r--lib/termsupport.zsh20
-rw-r--r--lib/theme-and-appearance.zsh2
5 files changed, 48 insertions, 25 deletions
diff --git a/lib/cli.zsh b/lib/cli.zsh
index 2189e24ca..4b14360c1 100644
--- a/lib/cli.zsh
+++ b/lib/cli.zsh
@@ -26,6 +26,7 @@ function _omz {
'help:Usage information'
'plugin:Manage plugins'
'pr:Manage Oh My Zsh Pull Requests'
+ 'reload:Reload the current zsh session'
'theme:Manage themes'
'update:Update Oh My Zsh'
)
@@ -35,7 +36,7 @@ function _omz {
elif (( CURRENT == 3 )); then
case "$words[2]" in
changelog) local -a refs
- refs=("${(@f)$(command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
+ refs=("${(@f)$(command git -C "$ZSH" for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
_describe 'command' refs ;;
plugin) subcmds=(
'disable:Disable plugin(s)'
@@ -90,7 +91,8 @@ function _omz {
# NOTE: $(( CURRENT - 1 )) is the last plugin argument completely passed, i.e. that which
# has a space after them. This is to avoid removing plugins partially passed, which makes
# the completion not add a space after the completed plugin.
- local -a args=(${words[4,$(( CURRENT - 1))]})
+ local -a args
+ args=(${words[4,$(( CURRENT - 1))]})
valid_plugins=(${valid_plugins:|args})
_describe 'plugin' valid_plugins ;;
@@ -159,6 +161,7 @@ Available commands:
changelog Print the changelog
plugin <command> Manage plugins
pr <command> Manage Oh My Zsh Pull Requests
+ reload Reload the current zsh session
theme <command> Manage themes
update Update Oh My Zsh
@@ -212,7 +215,7 @@ function _omz::plugin::disable {
fi
# Check that plugin is in $plugins
- local -a dis_plugins=()
+ local -a dis_plugins
for plugin in "$@"; do
if [[ ${plugins[(Ie)$plugin]} -eq 0 ]]; then
_omz::log warn "plugin '$plugin' is not enabled."
@@ -301,7 +304,7 @@ function _omz::plugin::enable {
fi
# Check that plugin is not in $plugins
- local -a add_plugins=()
+ local -a add_plugins
for plugin in "$@"; do
if [[ ${plugins[(Ie)$plugin]} -ne 0 ]]; then
_omz::log warn "plugin '$plugin' is already enabled."
@@ -422,10 +425,8 @@ function _omz::plugin::load {
return 1
fi
- local plugins=("$@")
local plugin base has_completion=0
-
- for plugin in $plugins; do
+ for plugin in "$@"; do
if [[ -d "$ZSH_CUSTOM/plugins/$plugin" ]]; then
base="$ZSH_CUSTOM/plugins/$plugin"
elif [[ -d "$ZSH/plugins/$plugin" ]]; then
@@ -598,6 +599,16 @@ function _omz::pr::test {
)
}
+function _omz::reload {
+ # Delete current completion cache
+ command rm -f $_comp_dumpfile $ZSH_COMPDUMP
+
+ # Old zsh versions don't have ZSH_ARGZERO
+ local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
+ # Check whether to run a login shell
+ [[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
+}
+
function _omz::theme {
(( $# > 0 && $+functions[_omz::theme::$1] )) || {
cat >&2 <<EOF
@@ -630,17 +641,23 @@ function _omz::theme::list {
return
fi
+ # Print theme in use
+ if [[ -n "$ZSH_THEME" ]]; then
+ print -Pn "%U%BCurrent theme%b%u: "
+ [[ $ZSH_THEME = random ]] && echo "$RANDOM_THEME (via random)" || echo "$ZSH_THEME"
+ echo
+ fi
+
+ # Print custom themes if there are any
if (( ${#custom_themes} )); then
print -P "%U%BCustom themes%b%u:"
print -l ${(q-)custom_themes} | column -x
+ echo
fi
- if (( ${#builtin_themes} )); then
- (( ${#custom_themes} )) && echo # add a line of separation
-
- print -P "%U%BBuilt-in themes%b%u:"
- print -l ${(q-)builtin_themes} | column -x
- fi
+ # Print built-in themes
+ print -P "%U%BBuilt-in themes%b%u:"
+ print -l ${(q-)builtin_themes} | column -x
}
function _omz::theme::set {
@@ -727,6 +744,10 @@ function _omz::theme::use {
_omz::log error "%B$1%b theme not found"
return 1
fi
+
+ # Update theme settings
+ ZSH_THEME="$1"
+ [[ $1 = random ]] || unset RANDOM_THEME
}
function _omz::update {
diff --git a/lib/correction.zsh b/lib/correction.zsh
index c635236b5..4259d3418 100644
--- a/lib/correction.zsh
+++ b/lib/correction.zsh
@@ -9,6 +9,7 @@ if [[ "$ENABLE_CORRECTION" == "true" ]]; then
alias mv='nocorrect mv'
alias mysql='nocorrect mysql'
alias sudo='nocorrect sudo'
+ alias su='nocorrect su'
setopt correct_all
fi
diff --git a/lib/git.zsh b/lib/git.zsh
index c9363274c..9a615e77b 100644
--- a/lib/git.zsh
+++ b/lib/git.zsh
@@ -206,7 +206,8 @@ function git_prompt_status() {
STASHED UNMERGED AHEAD BEHIND DIVERGED
)
- local status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)"
+ local status_text
+ status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)"
# Don't continue on a catastrophic failure
if [[ $? -eq 128 ]]; then
diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
index 33451ef1f..ef0d78895 100644
--- a/lib/termsupport.zsh
+++ b/lib/termsupport.zsh
@@ -10,7 +10,8 @@ function title {
emulate -L zsh
setopt prompt_subst
- [[ "$INSIDE_EMACS" == *term* ]] && return
+ # Don't set the title if inside emacs, unless using vterm
+ [[ -n "$INSIDE_EMACS" && "$INSIDE_EMACS" != vterm ]] && return
# if $2 is unset use $1 as default
# if it is set and empty, leave it as is
@@ -29,12 +30,9 @@ function title {
print -Pn "\e]2;${2:q}\a" # set window name
print -Pn "\e]1;${1:q}\a" # set tab name
else
- # Try to use terminfo to set the title
- # If the feature is available set title
- if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then
- echoti tsl
- print -Pn "$1"
- echoti fsl
+ # Try to use terminfo to set the title if the feature is available
+ if (( ${+terminfo[fsl]} && ${+terminfo[tsl]} )); then
+ print -Pn "${terminfo[tsl]}$1${terminfo[fsl]}"
fi
fi
;;
@@ -105,10 +103,12 @@ function omz_termsupport_preexec {
title '$CMD' '%100>...>$LINE%<<'
}
-autoload -U add-zsh-hook
-add-zsh-hook precmd omz_termsupport_precmd
-add-zsh-hook preexec omz_termsupport_preexec
+autoload -Uz add-zsh-hook
+if [[ -z "$INSIDE_EMACS" || "$INSIDE_EMACS" = vterm ]]; then
+ add-zsh-hook precmd omz_termsupport_precmd
+ add-zsh-hook preexec omz_termsupport_preexec
+fi
# Keep Apple Terminal.app's current working directory updated
# Based on this answer: https://superuser.com/a/315029
diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh
index 0b71de372..00947f72d 100644
--- a/lib/theme-and-appearance.zsh
+++ b/lib/theme-and-appearance.zsh
@@ -40,7 +40,7 @@ if [[ "$DISABLE_LS_COLORS" != "true" ]]; then
fi
# enable diff color if possible.
-if command diff --color . . &>/dev/null; then
+if command diff --color /dev/null /dev/null &>/dev/null; then
alias diff='diff --color'
fi