mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-17 23:57:52 +08:00
Compare commits
4 Commits
aca048814b
...
5cb943eea4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cb943eea4 | ||
|
|
bd9c216fe0 | ||
|
|
8a008e1f51 | ||
|
|
b54ef89fab |
@ -8,7 +8,7 @@ setopt pushdminus
|
||||
# to your `zshrc` before loading `oh-my-zsh.sh`
|
||||
# to disable the following aliases and functions
|
||||
|
||||
zstyle -T ':omz:directories' aliases || return
|
||||
zstyle -T ':omz:directories' aliases || return 0
|
||||
|
||||
alias -g ...='../..'
|
||||
alias -g ....='../../..'
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
# due to malicious input as a consequence of CVE-2021-45444, which affects
|
||||
# zsh versions from 5.0.3 to 5.8.
|
||||
#
|
||||
autoload -Uz +X regexp-replace VCS_INFO_formats 2>/dev/null || return
|
||||
autoload -Uz +X regexp-replace VCS_INFO_formats 2>/dev/null || return 0
|
||||
|
||||
# We use $tmp here because it's already a local variable in VCS_INFO_formats
|
||||
typeset PATCH='for tmp (base base-name branch misc revision subdir) hook_com[$tmp]="${hook_com[$tmp]//\%/%%}"'
|
||||
|
||||
@ -32,12 +32,14 @@ function _az-homebrew-installed() {
|
||||
(( $+commands[brew] )) || return 1
|
||||
|
||||
# speculatively check default brew prefix
|
||||
if [ -h /usr/local/opt/az ]; then
|
||||
_brew_prefix=/usr/local/opt/az
|
||||
if [[ -d /usr/local ]]; then
|
||||
_brew_prefix=/usr/local
|
||||
elif [[ -d /opt/homebrew ]]; then
|
||||
_brew_prefix=/opt/homebrew
|
||||
else
|
||||
# ok, it is not in the default prefix
|
||||
# this call to brew is expensive (about 400 ms), so at least let's make it only once
|
||||
_brew_prefix=$(brew --prefix azure-cli)
|
||||
_brew_prefix=$(brew --prefix)
|
||||
fi
|
||||
}
|
||||
|
||||
@ -49,12 +51,12 @@ _az_zsh_completer_path="$commands[az_zsh_completer.sh]"
|
||||
if [[ -z $_az_zsh_completer_path ]]; then
|
||||
# Homebrew
|
||||
if _az-homebrew-installed; then
|
||||
_az_zsh_completer_path=$_brew_prefix/libexec/bin/az.completion.sh
|
||||
_az_zsh_completer_path=$_brew_prefix/etc/bash_completion.d/az
|
||||
# Linux
|
||||
else
|
||||
_az_zsh_completer_path=/etc/bash_completion.d/azure-cli
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ -r $_az_zsh_completer_path ]] && source $_az_zsh_completer_path
|
||||
[[ -r $_az_zsh_completer_path ]] && autoload -U +X bashcompinit && bashcompinit && source $_az_zsh_completer_path
|
||||
unset _az_zsh_completer_path _brew_prefix
|
||||
|
||||
@ -2,11 +2,20 @@
|
||||
|
||||
This plugin adds a few functions that are useful when using [iTerm2](https://www.iterm2.com/).
|
||||
|
||||
|
||||
To use it, add _iterm2_ to the plugins array of your zshrc file:
|
||||
```
|
||||
plugins=(... iterm2)
|
||||
```
|
||||
|
||||
Optionally, the plugin also applies the [Shell Integration Script for iTerm2](https://iterm2.com/documentation-shell-integration.html).
|
||||
You can enable the integration with zstyle. It's important to add this line
|
||||
before the line sourcing oh-my-zsh:
|
||||
|
||||
```
|
||||
zstyle :omz:plugins:iterm2 shell-integration yes
|
||||
```
|
||||
|
||||
## Plugin commands
|
||||
|
||||
* `_iterm2_command <iterm2-command>`
|
||||
@ -24,6 +33,9 @@ plugins=(... iterm2)
|
||||
* `iterm2_tab_color_reset`
|
||||
resets the color of iTerm2's current tab back to default.
|
||||
|
||||
|
||||
For shell integration features see the [official documentation](https://iterm2.com/documentation-shell-integration.html).
|
||||
|
||||
## Contributors
|
||||
|
||||
- [Aviv Rosenberg](https://github.com/avivrosenberg)
|
||||
|
||||
@ -7,6 +7,17 @@
|
||||
# This plugin is only relevant if the terminal is iTerm2 on OSX.
|
||||
if [[ "$OSTYPE" == darwin* ]] && [[ -n "$ITERM_SESSION_ID" ]] ; then
|
||||
|
||||
# maybe make it the default in the future and allow opting out?
|
||||
if zstyle -t ':omz:plugins:iterm2' shell-integration; then
|
||||
# Handle $0 according to the standard:
|
||||
# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
|
||||
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
|
||||
0="${${(M)0:#/*}:-$PWD/$0}"
|
||||
|
||||
# See official docs: https://iterm2.com/documentation-shell-integration.html
|
||||
source "${0:A:h}/iterm2_shell_integration.zsh"
|
||||
fi
|
||||
|
||||
###
|
||||
# Executes an arbitrary iTerm2 command via an escape code sequence.
|
||||
# See https://iterm2.com/documentation-escape-codes.html for all supported commands.
|
||||
|
||||
178
plugins/iterm2/iterm2_shell_integration.zsh
Normal file
178
plugins/iterm2/iterm2_shell_integration.zsh
Normal file
@ -0,0 +1,178 @@
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
if [[ -o interactive ]]; then
|
||||
if [ "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}""$TERM" != "tmux-256color" -a "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}""$TERM" != "screen" -a "${ITERM_SHELL_INTEGRATION_INSTALLED-}" = "" -a "$TERM" != linux -a "$TERM" != dumb ]; then
|
||||
ITERM_SHELL_INTEGRATION_INSTALLED=Yes
|
||||
ITERM2_SHOULD_DECORATE_PROMPT="1"
|
||||
# Indicates start of command output. Runs just before command executes.
|
||||
iterm2_before_cmd_executes() {
|
||||
if [ "$TERM_PROGRAM" = "iTerm.app" ]; then
|
||||
printf "\033]133;C;\r\007"
|
||||
else
|
||||
printf "\033]133;C;\007"
|
||||
fi
|
||||
}
|
||||
|
||||
iterm2_set_user_var() {
|
||||
printf "\033]1337;SetUserVar=%s=%s\007" "$1" $(printf "%s" "$2" | base64 | tr -d '\n')
|
||||
}
|
||||
|
||||
# Users can write their own version of this method. It should call
|
||||
# iterm2_set_user_var but not produce any other output.
|
||||
# e.g., iterm2_set_user_var currentDirectory $PWD
|
||||
# Accessible in iTerm2 (in a badge now, elsewhere in the future) as
|
||||
# \(user.currentDirectory).
|
||||
whence -v iterm2_print_user_vars > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
iterm2_print_user_vars() {
|
||||
true
|
||||
}
|
||||
fi
|
||||
|
||||
iterm2_print_state_data() {
|
||||
local _iterm2_hostname="${iterm2_hostname-}"
|
||||
if [ -z "${iterm2_hostname:-}" ]; then
|
||||
_iterm2_hostname=$(hostname -f 2>/dev/null)
|
||||
fi
|
||||
printf "\033]1337;RemoteHost=%s@%s\007" "$USER" "${_iterm2_hostname-}"
|
||||
printf "\033]1337;CurrentDir=%s\007" "$PWD"
|
||||
iterm2_print_user_vars
|
||||
}
|
||||
|
||||
# Report return code of command; runs after command finishes but before prompt
|
||||
iterm2_after_cmd_executes() {
|
||||
printf "\033]133;D;%s\007" "$STATUS"
|
||||
iterm2_print_state_data
|
||||
}
|
||||
|
||||
# Mark start of prompt
|
||||
iterm2_prompt_mark() {
|
||||
printf "\033]133;A\007"
|
||||
}
|
||||
|
||||
# Mark end of prompt
|
||||
iterm2_prompt_end() {
|
||||
printf "\033]133;B\007"
|
||||
}
|
||||
|
||||
# There are three possible paths in life.
|
||||
#
|
||||
# 1) A command is entered at the prompt and you press return.
|
||||
# The following steps happen:
|
||||
# * iterm2_preexec is invoked
|
||||
# * PS1 is set to ITERM2_PRECMD_PS1
|
||||
# * ITERM2_SHOULD_DECORATE_PROMPT is set to 1
|
||||
# * The command executes (possibly reading or modifying PS1)
|
||||
# * iterm2_precmd is invoked
|
||||
# * ITERM2_PRECMD_PS1 is set to PS1 (as modified by command execution)
|
||||
# * PS1 gets our escape sequences added to it
|
||||
# * zsh displays your prompt
|
||||
# * You start entering a command
|
||||
#
|
||||
# 2) You press ^C while entering a command at the prompt.
|
||||
# The following steps happen:
|
||||
# * (iterm2_preexec is NOT invoked)
|
||||
# * iterm2_precmd is invoked
|
||||
# * iterm2_before_cmd_executes is called since we detected that iterm2_preexec was not run
|
||||
# * (ITERM2_PRECMD_PS1 and PS1 are not messed with, since PS1 already has our escape
|
||||
# sequences and ITERM2_PRECMD_PS1 already has PS1's original value)
|
||||
# * zsh displays your prompt
|
||||
# * You start entering a command
|
||||
#
|
||||
# 3) A new shell is born.
|
||||
# * PS1 has some initial value, either zsh's default or a value set before this script is sourced.
|
||||
# * iterm2_precmd is invoked
|
||||
# * ITERM2_SHOULD_DECORATE_PROMPT is initialized to 1
|
||||
# * ITERM2_PRECMD_PS1 is set to the initial value of PS1
|
||||
# * PS1 gets our escape sequences added to it
|
||||
# * Your prompt is shown and you may begin entering a command.
|
||||
#
|
||||
# Invariants:
|
||||
# * ITERM2_SHOULD_DECORATE_PROMPT is 1 during and just after command execution, and "" while the prompt is
|
||||
# shown and until you enter a command and press return.
|
||||
# * PS1 does not have our escape sequences during command execution
|
||||
# * After the command executes but before a new one begins, PS1 has escape sequences and
|
||||
# ITERM2_PRECMD_PS1 has PS1's original value.
|
||||
iterm2_decorate_prompt() {
|
||||
# This should be a raw PS1 without iTerm2's stuff. It could be changed during command
|
||||
# execution.
|
||||
ITERM2_PRECMD_PS1="$PS1"
|
||||
ITERM2_SHOULD_DECORATE_PROMPT=""
|
||||
|
||||
# Add our escape sequences just before the prompt is shown.
|
||||
# Use ITERM2_SQUELCH_MARK for people who can't mdoify PS1 directly, like powerlevel9k users.
|
||||
# This is gross but I had a heck of a time writing a correct if statetment for zsh 5.0.2.
|
||||
local PREFIX=""
|
||||
if [[ $PS1 == *"$(iterm2_prompt_mark)"* ]]; then
|
||||
PREFIX=""
|
||||
elif [[ "${ITERM2_SQUELCH_MARK-}" != "" ]]; then
|
||||
PREFIX=""
|
||||
else
|
||||
PREFIX="%{$(iterm2_prompt_mark)%}"
|
||||
fi
|
||||
PS1="$PREFIX$PS1%{$(iterm2_prompt_end)%}"
|
||||
ITERM2_DECORATED_PS1="$PS1"
|
||||
}
|
||||
|
||||
iterm2_precmd() {
|
||||
local STATUS="$?"
|
||||
if [ -z "${ITERM2_SHOULD_DECORATE_PROMPT-}" ]; then
|
||||
# You pressed ^C while entering a command (iterm2_preexec did not run)
|
||||
iterm2_before_cmd_executes
|
||||
if [ "$PS1" != "${ITERM2_DECORATED_PS1-}" ]; then
|
||||
# PS1 changed, perhaps in another precmd. See issue 9938.
|
||||
ITERM2_SHOULD_DECORATE_PROMPT="1"
|
||||
fi
|
||||
fi
|
||||
|
||||
iterm2_after_cmd_executes "$STATUS"
|
||||
|
||||
if [ -n "$ITERM2_SHOULD_DECORATE_PROMPT" ]; then
|
||||
iterm2_decorate_prompt
|
||||
fi
|
||||
}
|
||||
|
||||
# This is not run if you press ^C while entering a command.
|
||||
iterm2_preexec() {
|
||||
# Set PS1 back to its raw value prior to executing the command.
|
||||
PS1="$ITERM2_PRECMD_PS1"
|
||||
ITERM2_SHOULD_DECORATE_PROMPT="1"
|
||||
iterm2_before_cmd_executes
|
||||
}
|
||||
|
||||
# If hostname -f is slow on your system set iterm2_hostname prior to
|
||||
# sourcing this script. We know it is fast on macOS so we don't cache
|
||||
# it. That lets us handle the hostname changing like when you attach
|
||||
# to a VPN.
|
||||
if [ -z "${iterm2_hostname-}" ]; then
|
||||
if [ "$(uname)" != "Darwin" ]; then
|
||||
iterm2_hostname=`hostname -f 2>/dev/null`
|
||||
# Some flavors of BSD (i.e. NetBSD and OpenBSD) don't have the -f option.
|
||||
if [ $? -ne 0 ]; then
|
||||
iterm2_hostname=`hostname`
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ -z ${precmd_functions-} ]] && precmd_functions=()
|
||||
precmd_functions=($precmd_functions iterm2_precmd)
|
||||
|
||||
[[ -z ${preexec_functions-} ]] && preexec_functions=()
|
||||
preexec_functions=($preexec_functions iterm2_preexec)
|
||||
|
||||
iterm2_print_state_data
|
||||
printf "\033]1337;ShellIntegrationVersion=14;shell=zsh\007"
|
||||
fi
|
||||
fi
|
||||
4
plugins/iterm2/update
Executable file
4
plugins/iterm2/update
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
curl -s -L https://iterm2.com/shell_integration/zsh \
|
||||
-o iterm2_shell_integration.zsh
|
||||
@ -6,7 +6,8 @@
|
||||
# dashed separator size
|
||||
function afmagic_dashes {
|
||||
# check either virtualenv or condaenv variables
|
||||
local python_env="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}"
|
||||
local python_env_dir="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}"
|
||||
local python_env="${python_env_dir##*/}"
|
||||
|
||||
# if there is a python virtual environment and it is displayed in
|
||||
# the prompt, account for it when returning the number of dashes
|
||||
|
||||
Loading…
Reference in New Issue
Block a user