mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-06 02:51:32 +01:00
Merge 152954dd95 into bc3cadf5c8
This commit is contained in:
commit
358b0d2056
3 changed files with 241 additions and 30 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,7 +1,7 @@
|
||||||
locals.zsh
|
locals.zsh
|
||||||
log/.zsh_history
|
log/.zsh_history
|
||||||
projects.zsh
|
projects.zsh
|
||||||
custom/*
|
#custom/*
|
||||||
!custom/example
|
!custom/example
|
||||||
!custom/example.zsh
|
!custom/example.zsh
|
||||||
*.swp
|
*.swp
|
||||||
|
|
|
||||||
168
custom/powerline.zsh
Normal file
168
custom/powerline.zsh
Normal file
|
|
@ -0,0 +1,168 @@
|
||||||
|
autoload promptinit && promptinit || return 1
|
||||||
|
|
||||||
|
zmodload zsh/parameter
|
||||||
|
|
||||||
|
# has it been loaded correctly? if not, bail out early.
|
||||||
|
(( $+functions[prompt_powerline_setup] )) || return 2
|
||||||
|
|
||||||
|
# we can never know for sure powerline font is installed, but if we're on
|
||||||
|
# rxvt-unicode, chances are good. note that most zstyles have to be set before
|
||||||
|
# the prompt is loaded since they are not continuously re-evaluated.
|
||||||
|
#[[ $TERM == "rxvt-unicode-256color" ]] || return 3
|
||||||
|
|
||||||
|
### additional zstyles
|
||||||
|
|
||||||
|
# set some fixed host colors
|
||||||
|
zstyle ':prompt:*:twilight*' host-color 093
|
||||||
|
zstyle ':prompt:*:pinkie*' host-color 201
|
||||||
|
zstyle ':prompt:*:rarity' host-color white
|
||||||
|
zstyle ':prompt:*:applejack' host-color 208
|
||||||
|
zstyle ':prompt:*:fluttershy' host-color 226
|
||||||
|
|
||||||
|
# only show username on remote server or if it's different from my default
|
||||||
|
[[ -n $SSH_CONNECTION || $USER == valodim ]] && zstyle ':prompt:powerline:ps1' hide-user 1
|
||||||
|
|
||||||
|
# enable check-for-changes, for the ¹² indicators in git
|
||||||
|
zstyle ':vcs_info:*:powerline:*' check-for-changes true
|
||||||
|
|
||||||
|
|
||||||
|
### additional git info hooks
|
||||||
|
|
||||||
|
|
||||||
|
# Show remote ref name and number of commits ahead-of or behind
|
||||||
|
+vi-git-tracking () {
|
||||||
|
local ahead behind remote tmp
|
||||||
|
local -a formats
|
||||||
|
|
||||||
|
# Get tracking-formats, or bail out immediately
|
||||||
|
zstyle -a ":vcs_info:${vcs}:${usercontext}:${rrn}" trackingformats formats || return 0
|
||||||
|
|
||||||
|
# Are we on a remote-tracking branch?
|
||||||
|
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
|
||||||
|
--symbolic-full-name 2>/dev/null)/refs\/remotes\/}
|
||||||
|
|
||||||
|
if [[ -n ${remote} ]] ; then
|
||||||
|
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
|
||||||
|
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
|
||||||
|
if (( ahead && behind )); then
|
||||||
|
zformat -f tmp $formats[3] a:$ahead b:$behind
|
||||||
|
elif (( ahead )); then
|
||||||
|
zformat -f tmp $formats[1] a:$ahead
|
||||||
|
elif (( behind )); then
|
||||||
|
zformat -f tmp $formats[2] b:$behind
|
||||||
|
fi
|
||||||
|
|
||||||
|
hook_com[branch]+=$tmp
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Show count of stashed changes
|
||||||
|
+vi-git-stash () {
|
||||||
|
local -a stashes
|
||||||
|
local -a format
|
||||||
|
|
||||||
|
zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" stashformat format || return 0
|
||||||
|
|
||||||
|
if [[ -n $format && -s ${hook_com[base]}/.git/refs/stash ]] ; then
|
||||||
|
# find number of stashed commits
|
||||||
|
stashes=$(git stash list 2>/dev/null | wc -l)
|
||||||
|
(( stashes )) || return 0
|
||||||
|
|
||||||
|
# add to misc
|
||||||
|
zformat -f tmp $format s:$stashes
|
||||||
|
hook_com[misc]+=$tmp
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# install git hooks
|
||||||
|
zstyle ':vcs_info:git+set-message:*' hooks git-tracking git-stash
|
||||||
|
|
||||||
|
|
||||||
|
### lofi hook
|
||||||
|
|
||||||
|
|
||||||
|
# this is a hook which stops vcs_info right after the vcs detection step.
|
||||||
|
#
|
||||||
|
# this allows displaying a piece of information that the current PWD is inside
|
||||||
|
# a vcs repository and its type, without loading the heavyweight vcs data.
|
||||||
|
#
|
||||||
|
# this function was hardly tested with anything besides git, and probably has
|
||||||
|
# bugs.
|
||||||
|
#
|
||||||
|
+vi-lofi () {
|
||||||
|
|
||||||
|
# locals
|
||||||
|
local msg basedir subdir
|
||||||
|
local -i i
|
||||||
|
local -xA hook_com
|
||||||
|
local -xa msgs
|
||||||
|
|
||||||
|
# lofi mode enabled?
|
||||||
|
if ! zstyle -t ":vcs_info:${vcs}:${usercontext}:${PWD}" lofi ; then
|
||||||
|
# if not, just leave.
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# get lofi styles
|
||||||
|
zstyle -a ":vcs_info:${vcs}:${usercontext}:${rrn}" lofiformats msgs
|
||||||
|
|
||||||
|
# if no lofi styles are set, better chicken out here
|
||||||
|
(( $#msgs == 0 )) && return 0
|
||||||
|
|
||||||
|
# git has the only detect mechanism that does not set the basedir. sheesh.
|
||||||
|
if (( $+vcs_comm[gitdir] )); then
|
||||||
|
basedir=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
|
||||||
|
elif (( $+vcs_comm[basedir] )); then
|
||||||
|
basedir=$vcs_comm[basedir]
|
||||||
|
else
|
||||||
|
# no set? huh. just assume it's PWD, then...
|
||||||
|
basedir=$PWD
|
||||||
|
fi
|
||||||
|
# get subdir within repo tree
|
||||||
|
subdir="$(VCS_INFO_reposub ${basedir})"
|
||||||
|
|
||||||
|
# process the messages as usual, but with only the vcs name as %s
|
||||||
|
(( ${#msgs} > maxexports )) && msgs[$(( maxexports + 1 )),-1]=()
|
||||||
|
for i in {1..${#msgs}} ; do
|
||||||
|
if VCS_INFO_hook "set-lofi-message" $(( $i - 1 )) "${msgs[$i]}"; then
|
||||||
|
zformat -f msg ${msgs[$i]} s:${vcs} R:${basedir} S:${subdir}
|
||||||
|
msgs[$i]=${msg}
|
||||||
|
else
|
||||||
|
msgs[$i]=${hook_com[message]}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# this from msgs
|
||||||
|
VCS_INFO_set
|
||||||
|
|
||||||
|
# this is the value passed back up to vcs_info, which stops further processing
|
||||||
|
ret=1
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# function which disables lofi for this particular directory
|
||||||
|
prompt-unlofi-pwd () {
|
||||||
|
# disable lofi mode for this directory and all subdirs
|
||||||
|
zstyle ":vcs_info:*:*:$PWD*" lofi false
|
||||||
|
|
||||||
|
# if this is run as a widget, ...
|
||||||
|
if zle; then
|
||||||
|
# manually re-run all prompt precmd functions (so vcs_info is
|
||||||
|
# reevaluated as well), and reset prompt to update status.
|
||||||
|
for f in ${(M)precmd_functions#prompt_*_precmd}; $f
|
||||||
|
zle .reset-prompt
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
zle -N prompt-unlofi-pwd
|
||||||
|
bindkey '^G^L' prompt-unlofi-pwd
|
||||||
|
|
||||||
|
# lofi every directory by default
|
||||||
|
zstyle ':vcs_info:*' lofi true
|
||||||
|
# but not .zsh, that's small we always wanna see it
|
||||||
|
zstyle ":vcs_info:*:$HOME/.zsh*" lofi true
|
||||||
|
zstyle ':vcs_info-static_hooks:pre-get-data' hooks lofi
|
||||||
|
|
||||||
|
|
||||||
|
### actually select the prompt
|
||||||
|
|
||||||
|
prompt powerline
|
||||||
|
|
@ -2,37 +2,80 @@ alias bi="bower install"
|
||||||
alias bl="bower list"
|
alias bl="bower list"
|
||||||
alias bs="bower search"
|
alias bs="bower search"
|
||||||
|
|
||||||
bower_package_list=''
|
_bower_installed_packages () {
|
||||||
|
bower_package_list=$(bower ls --no-color 2>/dev/null| awk 'NR>3{print p}{p=$0}'| cut -d ' ' -f 2|sed 's/#.*//')
|
||||||
|
}
|
||||||
_bower ()
|
_bower ()
|
||||||
{
|
{
|
||||||
local curcontext="$curcontext" state line
|
local -a _1st_arguments _no_color _dopts _save_dev _force_lastest _production
|
||||||
typeset -A opt_args
|
local expl
|
||||||
|
typeset -A opt_args
|
||||||
|
|
||||||
_arguments -C \
|
_no_color=('--no-color[Do not print colors (available in all commands)]')
|
||||||
':command:->command' \
|
|
||||||
'*::options:->options'
|
|
||||||
|
|
||||||
case $state in
|
_dopts=(
|
||||||
(command)
|
'(--save)--save[Save installed packages into the project"s bower.json dependencies]'
|
||||||
|
'(--force)--force[Force fetching remote resources even if a local copy exists on disk]'
|
||||||
|
)
|
||||||
|
|
||||||
local -a subcommands
|
_save_dev=('(--save-dev)--save-dev[Save installed packages into the project"s bower.json devDependencies]')
|
||||||
subcommands=(${=$(bower help | grep help | sed -e 's/,//g')})
|
|
||||||
_describe -t commands 'bower' subcommands
|
|
||||||
;;
|
|
||||||
|
|
||||||
(options)
|
_force_lastest=('(--force-latest)--force-latest[Force latest version on conflict]')
|
||||||
case $line[1] in
|
|
||||||
|
_production=('(--production)--production[Do not install project devDependencies]')
|
||||||
|
|
||||||
|
_1st_arguments=(
|
||||||
|
'cache-clean:Clean the Bower cache, or the specified package caches' \
|
||||||
|
'help:Display help information about Bower' \
|
||||||
|
'info:Version info and description of a particular package' \
|
||||||
|
'init:Interactively create a bower.json file' \
|
||||||
|
'install:Install a package locally' \
|
||||||
|
'link:Symlink a package folder' \
|
||||||
|
'lookup:Look up a package URL by name' \
|
||||||
|
'register:Register a package' \
|
||||||
|
'search:Search for a package by name' \
|
||||||
|
'uninstall:Remove a package' \
|
||||||
|
'update:Update a package' \
|
||||||
|
{ls,list}:'[List all installed packages]'
|
||||||
|
)
|
||||||
|
_arguments \
|
||||||
|
$_no_color \
|
||||||
|
'*:: :->subcmds' && return 0
|
||||||
|
|
||||||
|
if (( CURRENT == 1 )); then
|
||||||
|
_describe -t commands "bower subcommand" _1st_arguments
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$words[1]" in
|
||||||
|
install)
|
||||||
|
_arguments \
|
||||||
|
$_dopts \
|
||||||
|
$_save_dev \
|
||||||
|
$_force_lastest \
|
||||||
|
$_no_color \
|
||||||
|
$_production
|
||||||
|
;;
|
||||||
|
update)
|
||||||
|
_arguments \
|
||||||
|
$_dopts \
|
||||||
|
$_no_color \
|
||||||
|
$_force_lastest
|
||||||
|
_bower_installed_packages
|
||||||
|
compadd "$@" $(echo $bower_package_list)
|
||||||
|
;;
|
||||||
|
uninstall)
|
||||||
|
_arguments \
|
||||||
|
$_no_color \
|
||||||
|
$_dopts
|
||||||
|
_bower_installed_packages
|
||||||
|
compadd "$@" $(echo $bower_package_list)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
$_no_color \
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
(install)
|
|
||||||
if [ -z "$bower_package_list" ];then
|
|
||||||
bower_package_list=$(bower search | awk 'NR > 2' | cut -d '-' -f 2 | cut -d ' ' -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")
|
|
||||||
fi
|
|
||||||
compadd "$@" $(echo $bower_package_list)
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compdef _bower bower
|
compdef _bower bower
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue