summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cli.zsh7
-rw-r--r--lib/clipboard.zsh10
-rw-r--r--lib/directories.zsh6
-rw-r--r--lib/functions.zsh2
-rw-r--r--lib/termsupport.zsh77
-rw-r--r--lib/theme-and-appearance.zsh36
6 files changed, 79 insertions, 59 deletions
diff --git a/lib/cli.zsh b/lib/cli.zsh
index fed00d21d..561c1b98b 100644
--- a/lib/cli.zsh
+++ b/lib/cli.zsh
@@ -11,7 +11,7 @@ function omz {
# Subcommand functions start with _ so that they don't
# appear as completion entries when looking for `omz`
- (( $+functions[_omz::$command] )) || {
+ (( ${+functions[_omz::$command]} )) || {
_omz::help
return 1
}
@@ -776,10 +776,11 @@ function _omz::update {
local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD)
# Run update script
+ zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
if [[ "$1" != --unattended ]]; then
- ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" --interactive || return $?
+ ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode || return $?
else
- ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" || return $?
+ ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -v $verbose_mode || return $?
fi
# Update last updated file
diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh
index 2f3b6bcad..4b37abc9b 100644
--- a/lib/clipboard.zsh
+++ b/lib/clipboard.zsh
@@ -100,8 +100,8 @@ function detect-clipboard() {
fi
}
-# Detect at startup. A non-zero exit here indicates that the dummy clipboards were set,
-# which is not really an error. If the user calls them, they will attempt to redetect
-# (for example, perhaps the user has now installed xclip) and then either print an error
-# or proceed successfully.
-detect-clipboard || true
+function clipcopy clippaste {
+ unfunction clipcopy clippaste
+ detect-clipboard || true # let one retry
+ "$0" "$@"
+}
diff --git a/lib/directories.zsh b/lib/directories.zsh
index 13b680c19..8927a56ad 100644
--- a/lib/directories.zsh
+++ b/lib/directories.zsh
@@ -4,12 +4,6 @@ setopt auto_pushd
setopt pushd_ignore_dups
setopt pushdminus
-# add (uncommented):
-# zstyle ':omz:directories' aliases no
-# to your `zshrc` before loading `oh-my-zsh.sh`
-# to disable the following aliases and functions
-
-zstyle -T ':omz:directories' aliases || return 0
alias -g ...='../..'
alias -g ....='../../..'
diff --git a/lib/functions.zsh b/lib/functions.zsh
index 1d85ea38a..a252d0a33 100644
--- a/lib/functions.zsh
+++ b/lib/functions.zsh
@@ -5,7 +5,7 @@ function zsh_stats() {
}
function uninstall_oh_my_zsh() {
- env ZSH="$ZSH" sh "$ZSH/tools/uninstall.sh"
+ command env ZSH="$ZSH" sh "$ZSH/tools/uninstall.sh"
}
function upgrade_oh_my_zsh() {
diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
index 80ca7ef78..d170ffcbf 100644
--- a/lib/termsupport.zsh
+++ b/lib/termsupport.zsh
@@ -17,7 +17,7 @@ function title {
: ${2=$1}
case "$TERM" in
- cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot)
+ cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot*|contour*)
print -Pn "\e]2;${2:q}\a" # set window name
print -Pn "\e]1;${1:q}\a" # set tab name
;;
@@ -109,28 +109,55 @@ if [[ -z "$INSIDE_EMACS" || "$INSIDE_EMACS" = vterm ]]; then
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
-# With extra fixes to handle multibyte chars and non-UTF-8 locales
-
-if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
- # Emits the control sequence to notify Terminal.app of the cwd
- # Identifies the directory using a file: URI scheme, including
- # the host name to disambiguate local vs. remote paths.
- function update_terminalapp_cwd() {
- emulate -L zsh
-
- # Percent-encode the host and path names.
- local URL_HOST URL_PATH
- URL_HOST="$(omz_urlencode -P $HOST)" || return 1
- URL_PATH="$(omz_urlencode -P $PWD)" || return 1
-
- # Undocumented Terminal.app-specific control sequence
- printf '\e]7;%s\a' "file://$URL_HOST$URL_PATH"
- }
-
- # Use a precmd hook instead of a chpwd hook to avoid contaminating output
- add-zsh-hook precmd update_terminalapp_cwd
- # Run once to get initial cwd set
- update_terminalapp_cwd
+# Keep terminal emulator's current working directory correct,
+# even if the current working directory path contains symbolic links
+#
+# References:
+# - Apple's Terminal.app: https://superuser.com/a/315029
+# - iTerm2: https://iterm2.com/documentation-escape-codes.html (iTerm2 Extension / CurrentDir+RemoteHost)
+# - Konsole: https://bugs.kde.org/show_bug.cgi?id=327720#c1
+# - libvte (gnome-terminal, mate-terminal, …): https://bugzilla.gnome.org/show_bug.cgi?id=675987#c14
+# Apparently it had a bug before ~2012 were it would display the unknown OSC 7 code
+#
+# As of May 2021 mlterm, PuTTY, rxvt, screen, termux & xterm simply ignore the unknown OSC.
+
+# Don't define the function if we're inside Emacs or in an SSH session (#11696)
+if [[ -n "$INSIDE_EMACS" || -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
+ return
fi
+
+# Don't define the function if we're in an unsupported terminal
+case "$TERM" in
+ # all of these either process OSC 7 correctly or ignore entirely
+ xterm*|putty*|rxvt*|konsole*|mlterm*|alacritty|screen*|tmux*) ;;
+ contour*|foot*) ;;
+ *)
+ # Terminal.app and iTerm2 process OSC 7 correctly
+ case "$TERM_PROGRAM" in
+ Apple_Terminal|iTerm.app) ;;
+ *) return ;;
+ esac ;;
+esac
+
+# Emits the control sequence to notify many terminal emulators
+# of the cwd
+#
+# Identifies the directory using a file: URI scheme, including
+# the host name to disambiguate local vs. remote paths.
+function omz_termsupport_cwd {
+ # Percent-encode the host and path names.
+ local URL_HOST URL_PATH
+ URL_HOST="$(omz_urlencode -P $HOST)" || return 1
+ URL_PATH="$(omz_urlencode -P $PWD)" || return 1
+
+ # Konsole errors if the HOST is provided
+ [[ -z "$KONSOLE_PROFILE_NAME" && -z "$KONSOLE_DBUS_SESSION" ]] || URL_HOST=""
+
+ # common control sequence (OSC 7) to set current host and path
+ printf "\e]7;file://%s%s\e\\" "${URL_HOST}" "${URL_PATH}"
+}
+
+# Use a precmd hook instead of a chpwd hook to avoid contaminating output
+# i.e. when a script or function changes directory without `cd -q`, chpwd
+# will be called the output may be swallowed by the script or function.
+add-zsh-hook precmd omz_termsupport_cwd
diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh
index d8859b04c..585e969d8 100644
--- a/lib/theme-and-appearance.zsh
+++ b/lib/theme-and-appearance.zsh
@@ -20,10 +20,25 @@ if command diff --color /dev/null{,} &>/dev/null; then
}
fi
-
# Don't set ls coloring if disabled
[[ "$DISABLE_LS_COLORS" != true ]] || return 0
+# Default coloring for BSD-based ls
+export LSCOLORS="Gxfxcxdxbxegedabagacad"
+
+# Default coloring for GNU-based ls
+if [[ -z "$LS_COLORS" ]]; then
+ # Define LS_COLORS via dircolors if available. Otherwise, set a default
+ # equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
+ if (( $+commands[dircolors] )); then
+ [[ -f "$HOME/.dircolors" ]] \
+ && source <(dircolors -b "$HOME/.dircolors") \
+ || source <(dircolors -b)
+ else
+ export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
+ fi
+fi
+
function test-ls-args {
local cmd="$1" # ls, gls, colorls, ...
local args="${@[2,-1]}" # arguments except the first one
@@ -50,7 +65,7 @@ case "$OSTYPE" in
test-ls-args ls -G && alias ls='ls -G'
# Only use GNU ls if installed and there are user defaults for $LS_COLORS,
# as the default coloring scheme is not very pretty
- [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] \
+ zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \
&& test-ls-args gls --color \
&& alias ls='gls --color=tty'
;;
@@ -64,20 +79,3 @@ case "$OSTYPE" in
esac
unfunction test-ls-args
-
-
-# Default coloring for BSD-based ls
-export LSCOLORS="Gxfxcxdxbxegedabagacad"
-
-# Default coloring for GNU-based ls
-if [[ -z "$LS_COLORS" ]]; then
- # Define LS_COLORS via dircolors if available. Otherwise, set a default
- # equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
- if (( $+commands[dircolors] )); then
- [[ -f "$HOME/.dircolors" ]] \
- && source <(dircolors -b "$HOME/.dircolors") \
- || source <(dircolors -b)
- else
- export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
- fi
-fi