mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-25 01:47:25 +08:00
Compare commits
6 Commits
47c04d921e
...
efcbd9f348
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efcbd9f348 | ||
|
|
172b32c90d | ||
|
|
53aefc52e2 | ||
|
|
6b0557afe8 | ||
|
|
f484f88b42 | ||
|
|
8b37f817c2 |
@ -1,7 +1,7 @@
|
|||||||
function zsh_stats() {
|
function zsh_stats() {
|
||||||
fc -l 1 \
|
fc -l 1 \
|
||||||
| awk '{ CMD[$2]++; count++; } END { for (a in CMD) print CMD[a] " " CMD[a]*100/count "% " a }' \
|
| awk '{ CMD[$2]++; count++; } END { for (a in CMD) print CMD[a] " " CMD[a]*100/count "% " a }' \
|
||||||
| grep -v "./" | sort -nr | head -n20 | column -c3 -s " " -t | nl
|
| grep -v "./" | sort -nr | head -20 | column -c3 -s " " -t | nl
|
||||||
}
|
}
|
||||||
|
|
||||||
function uninstall_oh_my_zsh() {
|
function uninstall_oh_my_zsh() {
|
||||||
|
|||||||
@ -51,7 +51,7 @@ function parse_git_dirty() {
|
|||||||
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
|
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n1)
|
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -1)
|
||||||
fi
|
fi
|
||||||
if [[ -n $STATUS ]]; then
|
if [[ -n $STATUS ]]; then
|
||||||
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||||
|
|||||||
@ -66,7 +66,7 @@ if [[ $use_sudo -eq 1 ]]; then
|
|||||||
alias di="sudo dpkg -i"
|
alias di="sudo dpkg -i"
|
||||||
|
|
||||||
# Remove ALL kernel images and headers EXCEPT the one in use
|
# Remove ALL kernel images and headers EXCEPT the one in use
|
||||||
alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n$(uname -r)))'
|
alias kclean='sudo aptitude remove -P "?and(~i~nlinux-(ima|hea) ?not(~n$(uname -r)))"'
|
||||||
|
|
||||||
|
|
||||||
# commands using su #########
|
# commands using su #########
|
||||||
@ -105,7 +105,7 @@ else
|
|||||||
alias di='su -lc "dpkg -i" root'
|
alias di='su -lc "dpkg -i" root'
|
||||||
|
|
||||||
# Remove ALL kernel images and headers EXCEPT the one in use
|
# Remove ALL kernel images and headers EXCEPT the one in use
|
||||||
alias kclean='su -lc "aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n$(uname -r)))" root'
|
alias kclean='su -lc "aptitude remove -P \"?and(~i~nlinux-(ima|hea) ?not(~n$(uname -r)))\"" root'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Completion ################################################################
|
# Completion ################################################################
|
||||||
|
|||||||
16
plugins/term_tab/README
Normal file
16
plugins/term_tab/README
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
term_tab - 'cwd' for all open zsh sessions
|
||||||
|
******************************************
|
||||||
|
|
||||||
|
What it does:
|
||||||
|
*************
|
||||||
|
This plugin allows to complete the 'cwd' of other Zsh sessions. Sounds
|
||||||
|
complicated but is rather simple. E.g. if you have three zsh sessions open, in
|
||||||
|
each session you are in a different folder, you can hit Ctrl+v in one session
|
||||||
|
to show you the current working directory of the other open zsh sessions.
|
||||||
|
|
||||||
|
How it works:
|
||||||
|
*************
|
||||||
|
* It uses 'pidof zsh' to determine all zsh PIDs
|
||||||
|
* It reads procfs to get the current working directory of this session
|
||||||
|
* Everything is fed into zsh's completion magic
|
||||||
41
plugins/term_tab/term_tab.plugin.zsh
Normal file
41
plugins/term_tab/term_tab.plugin.zsh
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# Copyright (C) 2014 Julian Vetter <death.jester@web.de>
|
||||||
|
#
|
||||||
|
# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
function _term_list(){
|
||||||
|
local -a expl
|
||||||
|
local -au dirs
|
||||||
|
|
||||||
|
PREFIX="$IPREFIX$PREFIX"
|
||||||
|
IPREFIX=
|
||||||
|
SUFFIX="$SUFFIX$ISUFFIX"
|
||||||
|
ISUFFIX=
|
||||||
|
|
||||||
|
[[ -o magicequalsubst ]] && compset -P '*='
|
||||||
|
|
||||||
|
case $OSTYPE in
|
||||||
|
solaris*) dirs=( ${(M)${${(f)"$(pgrep -U $UID -x zsh|xargs pwdx)"}:#$$:*}%%/*} ) ;;
|
||||||
|
linux*) dirs=( /proc/${^$(pidof zsh):#$$}/cwd(N:A) ) ;;
|
||||||
|
esac
|
||||||
|
dirs=( ${(D)dirs} )
|
||||||
|
|
||||||
|
compstate[pattern_match]='*'
|
||||||
|
_wanted directories expl 'current directory from other shell' \
|
||||||
|
compadd -Q -M "r:|/=* r:|=*" -f -a dirs
|
||||||
|
}
|
||||||
|
|
||||||
|
zle -C term_list menu-complete _generic
|
||||||
|
bindkey "^v" term_list
|
||||||
|
zstyle ':completion:term_list::::' completer _term_list
|
||||||
@ -100,13 +100,13 @@ function wrap_clipboard_widgets() {
|
|||||||
eval "
|
eval "
|
||||||
function ${wrapped_name}() {
|
function ${wrapped_name}() {
|
||||||
zle .${widget}
|
zle .${widget}
|
||||||
printf %s \"\${CUTBUFFER}\" | clipcopy
|
printf %s \"\${CUTBUFFER}\" | clipcopy 2>/dev/null || true
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
else
|
else
|
||||||
eval "
|
eval "
|
||||||
function ${wrapped_name}() {
|
function ${wrapped_name}() {
|
||||||
CUTBUFFER=\"\$(clippaste)\"
|
CUTBUFFER=\"\$(clippaste 2>/dev/null || echo \$CUTBUFFER)\"
|
||||||
zle .${widget}
|
zle .${widget}
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
|||||||
30
plugins/zbell/README.md
Normal file
30
plugins/zbell/README.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# zbell plugin
|
||||||
|
|
||||||
|
This plugin prints a bell character when a command finishes if it has been
|
||||||
|
running for longer than a specified duration.
|
||||||
|
|
||||||
|
To use it, add `zbell` to the plugins array in your zshrc file:
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
plugins=(... zbell)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
|
||||||
|
These settings need to be set in your zshrc file, before Oh My Zsh is sourced.
|
||||||
|
|
||||||
|
- `zbell_duration`: duration in seconds after which to consider notifying
|
||||||
|
the end of a command. Default: 15 seconds.
|
||||||
|
|
||||||
|
- `zbell_ignore`: if there are programs that you know run long that you
|
||||||
|
don't want to bell after, then add them to the `zbell_ignore` array.
|
||||||
|
By default, `$EDITOR` and `$PAGER` are ignored:
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
zbell_ignore=($EDITOR $PAGER)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
Adapted from an original version by [Jean-Philippe Ouellet](https://github.com/jpouellet).
|
||||||
|
Made available under the ISC license.
|
||||||
83
plugins/zbell/zbell.plugin.zsh
Normal file
83
plugins/zbell/zbell.plugin.zsh
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
# This script prints a bell character when a command finishes
|
||||||
|
# if it has been running for longer than $zbell_duration seconds.
|
||||||
|
# If there are programs that you know run long that you don't
|
||||||
|
# want to bell after, then add them to $zbell_ignore.
|
||||||
|
#
|
||||||
|
# This script uses only zsh builtins so its fast, there's no needless
|
||||||
|
# forking, and its only dependency is zsh and its standard modules
|
||||||
|
#
|
||||||
|
# Written by Jean-Philippe Ouellet <jpo@vt.edu>
|
||||||
|
# Made available under the ISC license.
|
||||||
|
|
||||||
|
# only do this if we're in an interactive shell
|
||||||
|
[[ -o interactive ]] || return
|
||||||
|
|
||||||
|
# get $EPOCHSECONDS. builtins are faster than date(1)
|
||||||
|
zmodload zsh/datetime || return
|
||||||
|
|
||||||
|
# make sure we can register hooks
|
||||||
|
autoload -Uz add-zsh-hook || return
|
||||||
|
|
||||||
|
# make sure we can do regexp replace
|
||||||
|
autoload -Uz regexp-replace || return
|
||||||
|
|
||||||
|
# initialize zbell_duration if not set
|
||||||
|
(( ${+zbell_duration} )) || zbell_duration=15
|
||||||
|
|
||||||
|
# initialize zbell_ignore if not set
|
||||||
|
(( ${+zbell_ignore} )) || zbell_ignore=($EDITOR $PAGER)
|
||||||
|
|
||||||
|
# initialize it because otherwise we compare a date and an empty string
|
||||||
|
# the first time we see the prompt. it's fine to have lastcmd empty on the
|
||||||
|
# initial run because it evaluates to an empty string, and splitting an
|
||||||
|
# empty string just results in an empty array.
|
||||||
|
zbell_timestamp=$EPOCHSECONDS
|
||||||
|
|
||||||
|
# default notification function
|
||||||
|
# $1: command
|
||||||
|
# $2: duration in seconds
|
||||||
|
zbell_notify() {
|
||||||
|
type notify-send > /dev/null && \
|
||||||
|
notify-send -i terminal "Command completed in ${2}s:" $1
|
||||||
|
print -n "\a"
|
||||||
|
}
|
||||||
|
|
||||||
|
# right before we begin to execute something, store the time it started at
|
||||||
|
zbell_begin() {
|
||||||
|
zbell_timestamp=$EPOCHSECONDS
|
||||||
|
zbell_lastcmd=$1
|
||||||
|
}
|
||||||
|
|
||||||
|
# when it finishes, if it's been running longer than $zbell_duration,
|
||||||
|
# and we dont have an ignored command in the line, then print a bell.
|
||||||
|
zbell_end() {
|
||||||
|
local cmd_duration=$(( $EPOCHSECONDS - $zbell_timestamp ))
|
||||||
|
local ran_long=$(( $cmd_duration >= $zbell_duration ))
|
||||||
|
|
||||||
|
local zbell_lastcmd_tmp="$zbell_lastcmd"
|
||||||
|
regexp-replace zbell_lastcmd_tmp '^sudo ' ''
|
||||||
|
|
||||||
|
[[ $zbell_last_timestamp == $zbell_timestamp ]] && return
|
||||||
|
|
||||||
|
[[ $zbell_lastcmd_tmp == "" ]] && return
|
||||||
|
|
||||||
|
zbell_last_timestamp=$zbell_timestamp
|
||||||
|
|
||||||
|
local has_ignored_cmd=0
|
||||||
|
for cmd in ${(s:;:)zbell_lastcmd_tmp//|/;}; do
|
||||||
|
words=(${(z)cmd})
|
||||||
|
util=${words[1]}
|
||||||
|
if (( ${zbell_ignore[(i)$util]} <= ${#zbell_ignore} )); then
|
||||||
|
has_ignored_cmd=1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
(( ! $has_ignored_cmd && ran_long )) && zbell_notify $zbell_lastcmd $cmd_duration
|
||||||
|
}
|
||||||
|
|
||||||
|
# register the functions as hooks
|
||||||
|
add-zsh-hook preexec zbell_begin
|
||||||
|
add-zsh-hook precmd zbell_end
|
||||||
@ -1,24 +1,14 @@
|
|||||||
# Theme with full path names and hostname
|
# My custom theme:
|
||||||
# Handy if you work on different servers all the time;
|
# - single line
|
||||||
|
# - quite simple by default: user@host:$PWD
|
||||||
local return_code="%(?..%{$fg_bold[red]%}%? ↵%{$reset_color%})"
|
# - green for local shell as non root
|
||||||
|
# - red for ssh shell as non root
|
||||||
function my_git_prompt_info() {
|
# - magenta for root sessions
|
||||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
|
# - prefix with remote address for ssh shells
|
||||||
GIT_STATUS=$(git_prompt_status)
|
# - prefix to detect docker containers or chroot
|
||||||
[[ -n $GIT_STATUS ]] && GIT_STATUS=" $GIT_STATUS"
|
# - git plugin to display current branch and status
|
||||||
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$GIT_STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Colored prompt
|
|
||||||
ZSH_THEME_COLOR_USER="green"
|
|
||||||
ZSH_THEME_COLOR_HOST="green"
|
|
||||||
ZSH_THEME_COLOR_PWD="yellow"
|
|
||||||
test -n "$SSH_CONNECTION" && ZSH_THEME_COLOR_USER="red" && ZSH_THEME_COLOR_HOST="red"
|
|
||||||
test `id -u` = 0 && ZSH_THEME_COLOR_USER="magenta" && ZSH_THEME_COLOR_HOST="magenta"
|
|
||||||
PROMPT='%{$fg_bold[$ZSH_THEME_COLOR_USER]%}%n@%{$fg_bold[$ZSH_THEME_COLOR_HOST]%}%M%{$reset_color%}:%{$fg_bold[$ZSH_THEME_COLOR_PWD]%}%~%{$reset_color%} $(my_git_prompt_info)%(!.#.$) '
|
|
||||||
RPS1="${return_code}"
|
|
||||||
|
|
||||||
|
# git plugin
|
||||||
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}("
|
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}("
|
||||||
ZSH_THEME_GIT_PROMPT_SUFFIX=") %{$reset_color%}"
|
ZSH_THEME_GIT_PROMPT_SUFFIX=") %{$reset_color%}"
|
||||||
ZSH_THEME_GIT_PROMPT_UNTRACKED="%%"
|
ZSH_THEME_GIT_PROMPT_UNTRACKED="%%"
|
||||||
@ -28,3 +18,33 @@ ZSH_THEME_GIT_PROMPT_RENAMED="~"
|
|||||||
ZSH_THEME_GIT_PROMPT_DELETED="!"
|
ZSH_THEME_GIT_PROMPT_DELETED="!"
|
||||||
ZSH_THEME_GIT_PROMPT_UNMERGED="?"
|
ZSH_THEME_GIT_PROMPT_UNMERGED="?"
|
||||||
|
|
||||||
|
function zsh_essembeh_gitstatus {
|
||||||
|
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
|
||||||
|
GIT_STATUS=$(git_prompt_status)
|
||||||
|
if [[ -n $GIT_STATUS ]]; then
|
||||||
|
GIT_STATUS=" $GIT_STATUS"
|
||||||
|
fi
|
||||||
|
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$GIT_STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX"
|
||||||
|
}
|
||||||
|
|
||||||
|
# by default, use green for user@host and no prefix
|
||||||
|
local ZSH_ESSEMBEH_COLOR="green"
|
||||||
|
local ZSH_ESSEMBEH_PREFIX=""
|
||||||
|
if [[ -n "$SSH_CONNECTION" ]]; then
|
||||||
|
# display the source address if connected via ssh
|
||||||
|
ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[$(echo $SSH_CONNECTION | awk '{print $1}')]%{$reset_color%} "
|
||||||
|
# use red color to highlight a remote connection
|
||||||
|
ZSH_ESSEMBEH_COLOR="red"
|
||||||
|
elif [[ -r /etc/debian_chroot ]]; then
|
||||||
|
# prefix prompt in case of chroot
|
||||||
|
ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[chroot:$(cat /etc/debian_chroot)]%{$reset_color%} "
|
||||||
|
elif [[ -r /.dockerenv ]]; then
|
||||||
|
# also prefix prompt inside a docker contrainer
|
||||||
|
ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[docker]%{$reset_color%} "
|
||||||
|
fi
|
||||||
|
if [[ $UID = 0 ]]; then
|
||||||
|
# always use magenta for root sessions, even in ssh
|
||||||
|
ZSH_ESSEMBEH_COLOR="magenta"
|
||||||
|
fi
|
||||||
|
PROMPT='${ZSH_ESSEMBEH_PREFIX}%{$fg[$ZSH_ESSEMBEH_COLOR]%}%n@%M%{$reset_color%}:%{%B$fg[yellow]%}%~%{$reset_color%b%} $(zsh_essembeh_gitstatus)%(!.#.$) '
|
||||||
|
RPROMPT="%(?..%{$fg[red]%}%?%{$reset_color%})"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user