mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-12 05:49:47 +08:00
Compare commits
3 Commits
31f2025e0f
...
7ef3f49f97
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ef3f49f97 | ||
|
|
efa8de0b52 | ||
|
|
b26000d168 |
@ -1,22 +1,20 @@
|
|||||||
## History wrapper
|
## History wrapper
|
||||||
function omz_history {
|
function omz_history {
|
||||||
local clear list
|
# parse arguments and remove from $@
|
||||||
zparseopts -E c=clear l=list
|
local clear list stamp
|
||||||
|
zparseopts -E -D c=clear l=list f=stamp E=stamp i=stamp
|
||||||
|
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
# if no arguments provided, show full history starting from 1
|
# if no arguments provided, show full history starting from 1
|
||||||
builtin fc -l 1
|
builtin fc $stamp -l 1
|
||||||
elif [[ -n "$clear" ]]; then
|
elif [[ -n "$clear" ]]; then
|
||||||
# if -c provided, clobber the history file
|
# if -c provided, clobber the history file
|
||||||
echo -n >| "$HISTFILE"
|
echo -n >| "$HISTFILE"
|
||||||
fc -p "$HISTFILE"
|
fc -p "$HISTFILE"
|
||||||
echo >&2 History file deleted.
|
echo >&2 History file deleted.
|
||||||
elif [[ -n "$list" ]]; then
|
|
||||||
# if -l provided, run as if calling `fc' directly
|
|
||||||
builtin fc "$@"
|
|
||||||
else
|
else
|
||||||
# otherwise, run `fc -l` with a custom format
|
# otherwise, run `fc -l` with a custom format
|
||||||
builtin fc -l "$@"
|
builtin fc $stamp -l "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,7 @@ The plugin also supports the following:
|
|||||||
| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) |
|
| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) |
|
||||||
| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) |
|
| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) |
|
||||||
| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled |
|
| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled |
|
||||||
|
| `ZSH_TMUX_AUTONAME_SESSION` | Automatically name new sessions based on the basename of `$PWD` (default: `false`) |
|
||||||
| `ZSH_TMUX_DETACHED` | Set the detached mode (default: `false`) |
|
| `ZSH_TMUX_DETACHED` | Set the detached mode (default: `false`) |
|
||||||
| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support |
|
| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support |
|
||||||
| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `tmux` if available, `screen` otherwise) |
|
| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `tmux` if available, `screen` otherwise) |
|
||||||
|
|||||||
@ -13,6 +13,8 @@ fi
|
|||||||
: ${ZSH_TMUX_AUTOCONNECT:=true}
|
: ${ZSH_TMUX_AUTOCONNECT:=true}
|
||||||
# Automatically close the terminal when tmux exits
|
# Automatically close the terminal when tmux exits
|
||||||
: ${ZSH_TMUX_AUTOQUIT:=$ZSH_TMUX_AUTOSTART}
|
: ${ZSH_TMUX_AUTOQUIT:=$ZSH_TMUX_AUTOSTART}
|
||||||
|
# Automatically name the new session based on the basename of PWD
|
||||||
|
: ${ZSH_TMUX_AUTONAME_SESSION:=false}
|
||||||
# Set term to screen or screen-256color based on current terminal support
|
# Set term to screen or screen-256color based on current terminal support
|
||||||
: ${ZSH_TMUX_DETACHED:=false}
|
: ${ZSH_TMUX_DETACHED:=false}
|
||||||
# Set detached mode
|
# Set detached mode
|
||||||
@ -102,9 +104,22 @@ function _zsh_tmux_plugin_run() {
|
|||||||
|
|
||||||
local _detached=""
|
local _detached=""
|
||||||
[[ "$ZSH_TMUX_DETACHED" == "true" ]] && _detached="-d"
|
[[ "$ZSH_TMUX_DETACHED" == "true" ]] && _detached="-d"
|
||||||
|
|
||||||
|
local session_name
|
||||||
|
if [[ "$ZSH_TMUX_AUTONAME_SESSION" == "true" ]]; then
|
||||||
|
# Name the session after the basename of the current directory
|
||||||
|
session_name=${PWD##*/}
|
||||||
|
# If the current directory is the home directory, name it 'HOME'
|
||||||
|
[[ "$PWD" == "$HOME" ]] && session_name="HOME"
|
||||||
|
# If the current directory is the root directory, name it 'ROOT'
|
||||||
|
[[ "$PWD" == "/" ]] && session_name="ROOT"
|
||||||
|
else
|
||||||
|
session_name="$ZSH_TMUX_DEFAULT_SESSION_NAME"
|
||||||
|
fi
|
||||||
|
|
||||||
# Try to connect to an existing session.
|
# Try to connect to an existing session.
|
||||||
if [[ -n "$ZSH_TMUX_DEFAULT_SESSION_NAME" ]]; then
|
if [[ -n "$session_name" ]]; then
|
||||||
[[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached -t $ZSH_TMUX_DEFAULT_SESSION_NAME
|
[[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached -t "$session_name"
|
||||||
else
|
else
|
||||||
[[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached
|
[[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached
|
||||||
fi
|
fi
|
||||||
@ -116,8 +131,9 @@ function _zsh_tmux_plugin_run() {
|
|||||||
elif [[ -e "$ZSH_TMUX_CONFIG" ]]; then
|
elif [[ -e "$ZSH_TMUX_CONFIG" ]]; then
|
||||||
tmux_cmd+=(-f "$ZSH_TMUX_CONFIG")
|
tmux_cmd+=(-f "$ZSH_TMUX_CONFIG")
|
||||||
fi
|
fi
|
||||||
if [[ -n "$ZSH_TMUX_DEFAULT_SESSION_NAME" ]]; then
|
|
||||||
$tmux_cmd new-session -s $ZSH_TMUX_DEFAULT_SESSION_NAME
|
if [[ -n "$session_name" ]]; then
|
||||||
|
$tmux_cmd new-session -s "$session_name"
|
||||||
else
|
else
|
||||||
$tmux_cmd new-session
|
$tmux_cmd new-session
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -96,7 +96,7 @@ prompt_context() {
|
|||||||
# Git: branch/detached head, dirty status
|
# Git: branch/detached head, dirty status
|
||||||
prompt_git() {
|
prompt_git() {
|
||||||
(( $+commands[git] )) || return
|
(( $+commands[git] )) || return
|
||||||
if [[ "$(git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then
|
if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local PL_BRANCH_CHAR
|
local PL_BRANCH_CHAR
|
||||||
@ -106,12 +106,12 @@ prompt_git() {
|
|||||||
}
|
}
|
||||||
local ref dirty mode repo_path
|
local ref dirty mode repo_path
|
||||||
|
|
||||||
if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then
|
if [[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then
|
||||||
repo_path=$(git rev-parse --git-dir 2>/dev/null)
|
repo_path=$(command git rev-parse --git-dir 2>/dev/null)
|
||||||
dirty=$(parse_git_dirty)
|
dirty=$(parse_git_dirty)
|
||||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
|
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
|
||||||
ref="◈ $(git describe --exact-match --tags HEAD 2> /dev/null)" || \
|
ref="◈ $(command git describe --exact-match --tags HEAD 2> /dev/null)" || \
|
||||||
ref="➦ $(git rev-parse --short HEAD 2> /dev/null)"
|
ref="➦ $(command git rev-parse --short HEAD 2> /dev/null)"
|
||||||
if [[ -n $dirty ]]; then
|
if [[ -n $dirty ]]; then
|
||||||
prompt_segment yellow black
|
prompt_segment yellow black
|
||||||
else
|
else
|
||||||
@ -119,8 +119,8 @@ prompt_git() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local ahead behind
|
local ahead behind
|
||||||
ahead=$(git log --oneline @{upstream}.. 2>/dev/null)
|
ahead=$(command git log --oneline @{upstream}.. 2>/dev/null)
|
||||||
behind=$(git log --oneline ..@{upstream} 2>/dev/null)
|
behind=$(command git log --oneline ..@{upstream} 2>/dev/null)
|
||||||
if [[ -n "$ahead" ]] && [[ -n "$behind" ]]; then
|
if [[ -n "$ahead" ]] && [[ -n "$behind" ]]; then
|
||||||
PL_BRANCH_CHAR=$'\u21c5'
|
PL_BRANCH_CHAR=$'\u21c5'
|
||||||
elif [[ -n "$ahead" ]]; then
|
elif [[ -n "$ahead" ]]; then
|
||||||
@ -163,10 +163,10 @@ prompt_bzr() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
local bzr_status status_mod status_all revision
|
local bzr_status status_mod status_all revision
|
||||||
if bzr_status=$(bzr status 2>&1); then
|
if bzr_status=$(command bzr status 2>&1); then
|
||||||
status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m)
|
status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m)
|
||||||
status_all=$(echo -n "$bzr_status" | head -n1 | wc -m)
|
status_all=$(echo -n "$bzr_status" | head -n1 | wc -m)
|
||||||
revision=${$(bzr log -r-1 --log-format line | cut -d: -f1):gs/%/%%}
|
revision=${$(command bzr log -r-1 --log-format line | cut -d: -f1):gs/%/%%}
|
||||||
if [[ $status_mod -gt 0 ]] ; then
|
if [[ $status_mod -gt 0 ]] ; then
|
||||||
prompt_segment yellow black "bzr@$revision ✚"
|
prompt_segment yellow black "bzr@$revision ✚"
|
||||||
else
|
else
|
||||||
@ -182,13 +182,13 @@ prompt_bzr() {
|
|||||||
prompt_hg() {
|
prompt_hg() {
|
||||||
(( $+commands[hg] )) || return
|
(( $+commands[hg] )) || return
|
||||||
local rev st branch
|
local rev st branch
|
||||||
if $(hg id >/dev/null 2>&1); then
|
if $(command hg id >/dev/null 2>&1); then
|
||||||
if $(hg prompt >/dev/null 2>&1); then
|
if $(command hg prompt >/dev/null 2>&1); then
|
||||||
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
|
if [[ $(command hg prompt "{status|unknown}") = "?" ]]; then
|
||||||
# if files are not added
|
# if files are not added
|
||||||
prompt_segment red white
|
prompt_segment red white
|
||||||
st='±'
|
st='±'
|
||||||
elif [[ -n $(hg prompt "{status|modified}") ]]; then
|
elif [[ -n $(command hg prompt "{status|modified}") ]]; then
|
||||||
# if any modification
|
# if any modification
|
||||||
prompt_segment yellow black
|
prompt_segment yellow black
|
||||||
st='±'
|
st='±'
|
||||||
@ -196,15 +196,15 @@ prompt_hg() {
|
|||||||
# if working copy is clean
|
# if working copy is clean
|
||||||
prompt_segment green $CURRENT_FG
|
prompt_segment green $CURRENT_FG
|
||||||
fi
|
fi
|
||||||
echo -n ${$(hg prompt "☿ {rev}@{branch}"):gs/%/%%} $st
|
echo -n ${$(command hg prompt "☿ {rev}@{branch}"):gs/%/%%} $st
|
||||||
else
|
else
|
||||||
st=""
|
st=""
|
||||||
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
|
rev=$(command hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
|
||||||
branch=$(hg id -b 2>/dev/null)
|
branch=$(command hg id -b 2>/dev/null)
|
||||||
if `hg st | grep -q "^\?"`; then
|
if command hg st | command grep -q "^\?"; then
|
||||||
prompt_segment red black
|
prompt_segment red black
|
||||||
st='±'
|
st='±'
|
||||||
elif `hg st | grep -q "^[MA]"`; then
|
elif command hg st | command grep -q "^[MA]"; then
|
||||||
prompt_segment yellow black
|
prompt_segment yellow black
|
||||||
st='±'
|
st='±'
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user