mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-09 02:24:03 +01:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
70aaa0d64a
17 changed files with 546 additions and 14 deletions
|
|
@ -1,7 +1,5 @@
|
|||
# get the name of the branch we are on
|
||||
function rvm_prompt_info() {
|
||||
ruby_version=$(~/.rvm/bin/rvm-prompt 2> /dev/null) || return
|
||||
echo "($ruby_version)"
|
||||
[[ ! -z $ruby_version ]] && echo "($ruby_version)"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ if [ $commands[autojump] ]; then # check if autojump is installed
|
|||
. /usr/share/autojump/autojump.zsh
|
||||
elif [ -f /etc/profile.d/autojump.zsh ]; then # manual installation
|
||||
. /etc/profile.d/autojump.zsh
|
||||
elif [ -f /opt/local/etc/profile.d/autojump.zsh ]; then # mac os x with ports
|
||||
. /opt/local/etc/profile.d/autojump.zsh
|
||||
elif [ $commands[brew] -a -f `brew --prefix`/etc/autojump ]; then # mac os x with brew
|
||||
. `brew --prefix`/etc/autojump
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ alias bu="bundle update"
|
|||
|
||||
# The following is based on https://github.com/gma/bundler-exec
|
||||
|
||||
bundled_commands=(annotate cap capify cucumber foreman guard middleman nanoc rackup rainbows rake rspec ruby shotgun spec spork thin thor unicorn unicorn_rails)
|
||||
bundled_commands=(annotate cap capify cucumber foreman guard middleman nanoc rackup rainbows rake rspec ruby shotgun spec spork thin thor unicorn unicorn_rails puma)
|
||||
|
||||
## Functions
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,30 @@
|
|||
function _cap_does_task_list_need_generating () {
|
||||
if [ ! -f .cap_tasks~ ]; then return 0;
|
||||
stat -f%m . > /dev/null 2>&1
|
||||
if [ "$?" = 0 ]; then
|
||||
stat_cmd=(stat -f%m)
|
||||
else
|
||||
stat_cmd=(stat -L --format=%y)
|
||||
fi
|
||||
|
||||
# Cache filename
|
||||
_cap_show_undescribed_tasks=0
|
||||
|
||||
# Cache filename
|
||||
_cap_task_cache_file='.cap_task_cache'
|
||||
|
||||
_cap_get_task_list () {
|
||||
if [ ${_cap_show_undescribed_tasks} -eq 0 ]; then
|
||||
cap -T | grep '^cap' | cut -d " " -f 2
|
||||
else
|
||||
accurate=$(stat -f%m .cap_tasks~)
|
||||
changed=$(stat -f%m config/deploy.rb)
|
||||
cap -vT | grep '^cap' | cut -d " " -f 2
|
||||
fi
|
||||
}
|
||||
|
||||
_cap_does_task_list_need_generating () {
|
||||
|
||||
if [ ! -f ${_cap_task_cache_file} ]; then return 0;
|
||||
else
|
||||
accurate=$($stat_cmd $_cap_task_cache_file)
|
||||
changed=$($stat_cmd config/deploy.rb)
|
||||
return $(expr $accurate '>=' $changed)
|
||||
fi
|
||||
}
|
||||
|
|
@ -10,12 +32,10 @@ function _cap_does_task_list_need_generating () {
|
|||
function _cap () {
|
||||
if [ -f config/deploy.rb ]; then
|
||||
if _cap_does_task_list_need_generating; then
|
||||
echo "\nGenerating .cap_tasks~..." > /dev/stderr
|
||||
cap show_tasks -q | cut -d " " -f 1 | sed -e '/^ *$/D' -e '1,2D'
|
||||
> .cap_tasks~
|
||||
_cap_get_task_list > ${_cap_task_cache_file}
|
||||
fi
|
||||
compadd `cat .cap_tasks~`
|
||||
compadd `cat ${_cap_task_cache_file}`
|
||||
fi
|
||||
}
|
||||
|
||||
compctl -K _cap cap
|
||||
compdef _cap cap
|
||||
|
|
|
|||
6
plugins/colemak/colemak-less
Normal file
6
plugins/colemak/colemak-less
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
n forw-line
|
||||
e back-line
|
||||
k repeat-search
|
||||
\ek repeat-search-all
|
||||
K reverse-search
|
||||
\eK reverse-search-all
|
||||
22
plugins/colemak/colemak.plugin.zsh
Normal file
22
plugins/colemak/colemak.plugin.zsh
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# ctrl-j newline
|
||||
bindkey '^n' accept-line
|
||||
bindkey -a '^n' accept-line
|
||||
|
||||
# another rotation to match qwerty
|
||||
bindkey -a 'n' down-line-or-history
|
||||
bindkey -a 'e' up-line-or-history
|
||||
bindkey -a 'i' vi-forward-char
|
||||
|
||||
# make qwerty
|
||||
bindkey -a 'k' vi-repeat-search
|
||||
bindkey -a 'K' vi-rev-repeat-search
|
||||
bindkey -a 'u' vi-insert
|
||||
bindkey -a 'U' vi-insert-bol
|
||||
bindkey -a 'l' vi-undo-change
|
||||
bindkey -a 'N' vi-join
|
||||
|
||||
# spare
|
||||
bindkey -a 'j' vi-forward-word-end
|
||||
bindkey -a 'J' vi-forward-blank-word-end
|
||||
|
||||
lesskey $ZSH_CUSTOM/plugins/colemak/colemak-less
|
||||
29
plugins/composer/composer.plugin.zsh
Normal file
29
plugins/composer/composer.plugin.zsh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# ------------------------------------------------------------------------------
|
||||
# FILE: composer.plugin.zsh
|
||||
# DESCRIPTION: oh-my-zsh composer plugin file.
|
||||
# AUTHOR: Daniel Gomes (me@danielcsgomes.com)
|
||||
# VERSION: 1.0.0
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Composer basic command completion
|
||||
_composer_get_command_list () {
|
||||
composer --no-ansi | sed "1,/Available commands/d" | awk '/^ [a-z]+/ { print $1 }'
|
||||
}
|
||||
|
||||
_composer () {
|
||||
if [ -f composer.json ]; then
|
||||
compadd `_composer_get_command_list`
|
||||
fi
|
||||
}
|
||||
|
||||
compdef _composer composer
|
||||
|
||||
# Aliases
|
||||
alias c='composer'
|
||||
alias csu='composer self-update'
|
||||
alias cu='composer update'
|
||||
alias ci='composer install'
|
||||
alias ccp='composer create-project'
|
||||
|
||||
# install composer in the current directory
|
||||
alias cget='curl -s https://getcomposer.org/installer | php'
|
||||
22
plugins/jira/jira.plugin.zsh
Normal file
22
plugins/jira/jira.plugin.zsh
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# To use: add a .jira-url file in the base of your project
|
||||
# Setup: cd to/my/project
|
||||
# echo "https://name.jira.com" >> .jira-url
|
||||
# Usage: jira # opens a new issue
|
||||
# jira ABC-123 # Opens an existing issue
|
||||
open_jira_issue () {
|
||||
if [ ! -f .jira-url ]; then
|
||||
echo "There is no .jira-url file in the current directory..."
|
||||
return 0;
|
||||
else
|
||||
jira_url=$(cat .jira-url);
|
||||
if [ -z "$1" ]; then
|
||||
echo "Opening new issue";
|
||||
`open $jira_url/secure/CreateIssue!default.jspa`;
|
||||
else
|
||||
echo "Opening issue #$1";
|
||||
`open $jira_url/issues/$1`;
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
alias jira='open_jira_issue'
|
||||
44
plugins/nanoc/_nanoc
Normal file
44
plugins/nanoc/_nanoc
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#compdef nanoc
|
||||
#autoload
|
||||
|
||||
# nanoc zsh completion - based on the homebrew zsh completion
|
||||
# requires the 'nanoc' gem to be installed
|
||||
|
||||
local -a _1st_arguments
|
||||
_1st_arguments=(
|
||||
'autocompile:start the autocompiler'
|
||||
'compile:compile items of this site'
|
||||
'create-item:create an item'
|
||||
'create-layout:create a layout'
|
||||
'create-site:create a site'
|
||||
'deploy:deploy the compiled site'
|
||||
'help:show help'
|
||||
'prune:remove files not managed by nanoc from the output directory'
|
||||
'show-data:show data in this site'
|
||||
'show-plugins:show all available plugins'
|
||||
'show-rules:describe the rules for each item'
|
||||
'update:update the data stored by the data source to a newer version'
|
||||
'validate-css:validate the site’s CSS'
|
||||
'validate-html:validate the site’s HTML'
|
||||
'validate-links:validate links in site'
|
||||
'view:start the web server that serves static files'
|
||||
'watch:start the watcher'
|
||||
)
|
||||
|
||||
local expl
|
||||
local -a pkgs installed_pkgs
|
||||
|
||||
_arguments \
|
||||
'(--color)--color[enable color]' \
|
||||
'(--debug)--debug[enable debugging]' \
|
||||
'(--help)--help[show the help message and quit]' \
|
||||
'(--no-color)--no-color[disable color]' \
|
||||
'(--verbose)--verbose[make nanoc output more detailed]' \
|
||||
'(--version)--version[show version information and quit]' \
|
||||
'(--warn)--warn[enable warnings]' \
|
||||
'*:: :->subcmds' && return 0
|
||||
|
||||
if (( CURRENT == 1 )); then
|
||||
_describe -t commands "nanoc subcommand" _1st_arguments
|
||||
return
|
||||
fi
|
||||
9
plugins/nanoc/nanoc.plugin.zsh
Normal file
9
plugins/nanoc/nanoc.plugin.zsh
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
alias n='nanoc'
|
||||
alias na='nanoc autocompile'
|
||||
alias nco='nanoc compile'
|
||||
alias nci='nanoc create_item'
|
||||
alias ncl='nanoc create_layout'
|
||||
alias ncs='nanoc create_site'
|
||||
alias nd='nanoc deploy'
|
||||
alias nv='nanoc view'
|
||||
alias nw='nanoc watch'
|
||||
148
plugins/per-directory-history/per-directory-history.plugin.zsh
Normal file
148
plugins/per-directory-history/per-directory-history.plugin.zsh
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
#!/usr/bin/env zsh
|
||||
#
|
||||
# This is a implementation of per directory history for zsh, some
|
||||
# implementations of which exist in bash[1,2]. It also implements
|
||||
# a per-directory-history-toggle-history function to change from using the
|
||||
# directory history to using the global history. In both cases the history is
|
||||
# always saved to both the global history and the directory history, so the
|
||||
# toggle state will not effect the saved histories. Being able to switch
|
||||
# between global and directory histories on the fly is a novel feature as far
|
||||
# as I am aware.
|
||||
#
|
||||
#-------------------------------------------------------------------------------
|
||||
# Configuration
|
||||
#-------------------------------------------------------------------------------
|
||||
#
|
||||
# HISTORY_BASE a global variable that defines the base directory in which the
|
||||
# directory histories are stored
|
||||
#
|
||||
#-------------------------------------------------------------------------------
|
||||
# History
|
||||
#-------------------------------------------------------------------------------
|
||||
#
|
||||
# The idea/inspiration for a per directory history is from Stewart MacArthur[1]
|
||||
# and Dieter[2], the implementation idea is from Bart Schaefer on the the zsh
|
||||
# mailing list[3]. The implementation is by Jim Hester in September 2012.
|
||||
#
|
||||
# [1]: http://www.compbiome.com/2010/07/bash-per-directory-bash-history.html
|
||||
# [2]: http://dieter.plaetinck.be/per_directory_bash
|
||||
# [3]: http://www.zsh.org/mla/users/1997/msg00226.html
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# Copyright (c) 2012 Jim Hester
|
||||
#
|
||||
# This software is provided 'as-is', without any express or implied warranty.
|
||||
# In no event will the authors be held liable for any damages arising from the
|
||||
# use of this software.
|
||||
#
|
||||
# Permission is granted to anyone to use this software for any purpose,
|
||||
# including commercial applications, and to alter it and redistribute it
|
||||
# freely, subject to the following restrictions:
|
||||
#
|
||||
# 1. The origin of this software must not be misrepresented; you must not claim
|
||||
# that you wrote the original software. If you use this software in a product,
|
||||
# an acknowledgment in the product documentation would be appreciated but is
|
||||
# not required.
|
||||
#
|
||||
# 2. Altered source versions must be plainly marked as such, and must not be
|
||||
# misrepresented as being the original software.
|
||||
#
|
||||
# 3. This notice may not be removed or altered from any source distribution..
|
||||
#
|
||||
################################################################################
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# configuration, the base under which the directory histories are stored
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
[[ -z $HISTORY_BASE ]] && HISTORY_BASE="$HOME/.directory_history"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# toggle global/directory history used for searching - ctrl-G by default
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
function per-directory-history-toggle-history() {
|
||||
if [[ $_per_directory_history_is_global == true ]]; then
|
||||
_per-directory-history-set-directory-history
|
||||
echo "using local history\n"
|
||||
else
|
||||
_per-directory-history-set-global-history
|
||||
echo "using global history\n"
|
||||
fi
|
||||
zle reset-prompt
|
||||
}
|
||||
|
||||
autoload per-directory-history-toggle-history
|
||||
zle -N per-directory-history-toggle-history
|
||||
bindkey '^G' per-directory-history-toggle-history
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# implementation details
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
_per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
|
||||
|
||||
function _per-directory-history-change-directory() {
|
||||
_per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
|
||||
mkdir -p ${_per_directory_history_directory:h}
|
||||
if [[ $_per_directory_history_is_global == false ]]; then
|
||||
#save to the global history
|
||||
fc -AI $HISTFILE
|
||||
#save history to previous file
|
||||
local prev="$HISTORY_BASE${OLDPWD:A}/history"
|
||||
mkdir -p ${prev:h}
|
||||
fc -AI $prev
|
||||
|
||||
#discard previous directory's history
|
||||
local original_histsize=$HISTSIZE
|
||||
HISTSIZE=0
|
||||
HISTSIZE=$original_histsize
|
||||
|
||||
#read history in new file
|
||||
if [[ -e $_per_directory_history_directory ]]; then
|
||||
fc -R $_per_directory_history_directory
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function _per-directory-history-addhistory() {
|
||||
print -sr -- ${1%%$'\n'}
|
||||
fc -p $_per_directory_history_directory
|
||||
}
|
||||
|
||||
|
||||
function _per-directory-history-set-directory-history() {
|
||||
if [[ $_per_directory_history_is_global == true ]]; then
|
||||
fc -AI $HISTFILE
|
||||
local original_histsize=$HISTSIZE
|
||||
HISTSIZE=0
|
||||
HISTSIZE=$original_histsize
|
||||
if [[ -e "$_per_directory_history_directory" ]]; then
|
||||
fc -R "$_per_directory_history_directory"
|
||||
fi
|
||||
fi
|
||||
_per_directory_history_is_global=false
|
||||
}
|
||||
function _per-directory-history-set-global-history() {
|
||||
if [[ $_per_directory_history_is_global == false ]]; then
|
||||
fc -AI $_per_directory_history_directory
|
||||
local original_histsize=$HISTSIZE
|
||||
HISTSIZE=0
|
||||
HISTSIZE=$original_histsize
|
||||
if [[ -e "$HISTFILE" ]]; then
|
||||
fc -R "$HISTFILE"
|
||||
fi
|
||||
fi
|
||||
_per_directory_history_is_global=true
|
||||
}
|
||||
|
||||
|
||||
#add functions to the exec list for chpwd and zshaddhistory
|
||||
chpwd_functions=(${chpwd_functions[@]} "_per-directory-history-change-directory")
|
||||
zshaddhistory_functions=(${zshaddhistory_functions[@]} "_per-directory-history-addhistory")
|
||||
|
||||
#start in directory mode
|
||||
mkdir -p ${_per_directory_history_directory:h}
|
||||
_per_directory_history_is_global=true
|
||||
_per-directory-history-set-directory-history
|
||||
|
|
@ -10,4 +10,8 @@ _symfony2 () {
|
|||
fi
|
||||
}
|
||||
|
||||
compdef _symfony2 app/console
|
||||
compdef _symfony2 app/console
|
||||
|
||||
#Alias
|
||||
alias sf2='php app/console'
|
||||
alias sf2clear='php app/console cache:clear'
|
||||
9
plugins/urltools/urltools.plugin.zsh
Normal file
9
plugins/urltools/urltools.plugin.zsh
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# URL Tools
|
||||
# Adds handy command line aliases useful for dealing with URLs
|
||||
#
|
||||
# Taken from:
|
||||
# http://ruslanspivak.com/2010/06/02/urlencode-and-urldecode-from-a-command-line/
|
||||
|
||||
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
|
||||
|
||||
alias urldecode='python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])"'
|
||||
|
|
@ -5,7 +5,12 @@ function zle-line-init zle-keymap-select {
|
|||
zle -N zle-line-init
|
||||
zle -N zle-keymap-select
|
||||
|
||||
#changing mode clobbers the keybinds, so store the keybinds before and execute
|
||||
#them after
|
||||
binds=`bindkey -L`
|
||||
bindkey -v
|
||||
for bind in ${(@f)binds}; do eval $bind; done
|
||||
unset binds
|
||||
|
||||
# if mode indicator wasn't setup by theme, define default
|
||||
if [[ "$MODE_INDICATOR" == "" ]]; then
|
||||
|
|
|
|||
41
plugins/zeus/README.md
Normal file
41
plugins/zeus/README.md
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
## zeus
|
||||
**Maintainer:** [b4mboo](https://github.com/b4mboo)
|
||||
|
||||
* `zi` aliases `zeus init`
|
||||
* `zinit` aliases `zeus init`
|
||||
|
||||
* `zs` aliases `zeus start`
|
||||
* `ztart` aliases `zeus start`
|
||||
|
||||
* `zc` aliases `zeus console`
|
||||
* `zonsole` aliases `zeus console`
|
||||
|
||||
* `zsr` aliases `zeus server`
|
||||
* `zerver` aliases `zeus server`
|
||||
|
||||
* `zr` aliases `zeus rake`
|
||||
* `zake` aliases `zeus rake`
|
||||
|
||||
* `zg` aliases `zeus generate`
|
||||
* `zenerate` aliases `zeus generate`
|
||||
|
||||
* `zrn` aliases `zeus runner`
|
||||
* `zunner` aliases `zeus runner`
|
||||
|
||||
* `zcu` aliases `zeus cucumber`
|
||||
* `zucumber` aliases `zeus cucumber`
|
||||
|
||||
* `zt` aliases `zeus test`
|
||||
* `zest` aliases `zeus test`
|
||||
|
||||
* `zu` aliases `zeus test test/unit/*`
|
||||
* `zunits` aliases `zeus test test/unit/*`
|
||||
|
||||
* `zf` aliases `zeus test test/functional/*`
|
||||
* `zunctional` aliases `zeus test test/functional/*`
|
||||
|
||||
* `za` aliases `zeus test test/unit/*; zeus test test/functional/; zeus cucumber`
|
||||
* `zall` aliases `zeus test test/unit/*; zeus test test/functional/; zeus cucumber`
|
||||
|
||||
* `zsw` aliases `rm .zeus.sock`
|
||||
* `zweep` aliases `rm .zeus.sock`
|
||||
58
plugins/zeus/zeus.plugin.zsh
Normal file
58
plugins/zeus/zeus.plugin.zsh
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
# Some aliases for zeus. (See: https://github.com/burke/zeus)
|
||||
# Zeus preloads your Rails environment and forks that process whenever
|
||||
# needed. This effectively speeds up Rails' boot process to under 1 sec.
|
||||
|
||||
# Always use bundler.
|
||||
# Rails depends on bundler, so we can be pretty sure, that there are no
|
||||
# problems with this command. For all the other aliases I provided an
|
||||
# alternative, in case people have conflicts with other plugins (e.g. suse).
|
||||
alias zeus='bundle exec zeus'
|
||||
|
||||
# Init
|
||||
alias zi='zeus init'
|
||||
alias zinit='zeus init'
|
||||
|
||||
# Start
|
||||
alias zs='zeus start'
|
||||
alias ztart='zeus start'
|
||||
|
||||
# Console
|
||||
alias zc='zeus console'
|
||||
alias zonsole='zeus console'
|
||||
|
||||
# Server
|
||||
alias zsr='zeus server'
|
||||
alias zerver='zeus server'
|
||||
|
||||
# Rake
|
||||
alias zr='zeus rake'
|
||||
alias zake='zeus rake'
|
||||
|
||||
# Generate
|
||||
alias zg='zeus generate'
|
||||
alias zenerate='zeus generate'
|
||||
|
||||
# Runner
|
||||
alias zrn='zeus runner'
|
||||
alias zunner='zeus runner'
|
||||
|
||||
# Cucumber
|
||||
alias zcu='zeus cucumber'
|
||||
alias zucumber='zeus cucumber'
|
||||
|
||||
# Test
|
||||
alias zt='zeus test'
|
||||
alias zest='zeus test'
|
||||
|
||||
alias zu='zeus test test/unit/*'
|
||||
alias zunits='zeus test test/unit/*'
|
||||
|
||||
alias zf='zeus test test/functional/*'
|
||||
alias zunctional='zeus test test/functional/*'
|
||||
|
||||
alias za='zeus test test/unit/*; zeus test test/functional/; zeus cucumber'
|
||||
alias zall='zeus test test/unit/*; zeus test test/functional/; zeus cucumber'
|
||||
|
||||
# Clean up crashed zeus instances.
|
||||
alias zsw='rm .zeus.sock'
|
||||
alias zweep='rm .zeus.sock'
|
||||
115
themes/agnoster.zsh-theme
Normal file
115
themes/agnoster.zsh-theme
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
# vim:ft=zsh ts=2 sw=2 sts=2
|
||||
#
|
||||
# agnoster's Theme - https://gist.github.com/3712874
|
||||
# A Powerline-inspired theme for ZSH
|
||||
#
|
||||
# # README
|
||||
#
|
||||
# In order for this theme to render correctly, you will need a
|
||||
# [Powerline-patched font](https://gist.github.com/1595572).
|
||||
#
|
||||
# In addition, I recommend the
|
||||
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
|
||||
# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app -
|
||||
# it has significantly better color fidelity.
|
||||
#
|
||||
# # Goals
|
||||
#
|
||||
# The aim of this theme is to only show you *relevant* information. Like most
|
||||
# prompts, it will only show git information when in a git working directory.
|
||||
# However, it goes a step further: everything from the current user and
|
||||
# hostname to whether the last call exited with an error to whether background
|
||||
# jobs are running in this shell will all be displayed automatically when
|
||||
# appropriate.
|
||||
|
||||
### Segment drawing
|
||||
# A few utility functions to make it easy and re-usable to draw segmented prompts
|
||||
|
||||
CURRENT_BG='NONE'
|
||||
SEGMENT_SEPARATOR='⮀'
|
||||
|
||||
# Begin a segment
|
||||
# Takes two arguments, background and foreground. Both can be omitted,
|
||||
# rendering default background/foreground.
|
||||
prompt_segment() {
|
||||
local bg fg
|
||||
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
|
||||
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
|
||||
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
|
||||
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
|
||||
else
|
||||
echo -n "%{$bg%}%{$fg%} "
|
||||
fi
|
||||
CURRENT_BG=$1
|
||||
[[ -n $3 ]] && echo -n $3
|
||||
}
|
||||
|
||||
# End the prompt, closing any open segments
|
||||
prompt_end() {
|
||||
if [[ -n $CURRENT_BG ]]; then
|
||||
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
|
||||
else
|
||||
echo -n "%{%k%}"
|
||||
fi
|
||||
echo -n "%{%f%}"
|
||||
CURRENT_BG=''
|
||||
}
|
||||
|
||||
### Prompt components
|
||||
# Each component will draw itself, and hide itself if no information needs to be shown
|
||||
|
||||
# Context: user@hostname (who am I and where am I)
|
||||
prompt_context() {
|
||||
local user=`whoami`
|
||||
|
||||
if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
|
||||
prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m"
|
||||
fi
|
||||
}
|
||||
|
||||
# Git: branch/detached head, dirty status
|
||||
prompt_git() {
|
||||
local ref dirty
|
||||
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY='±'
|
||||
dirty=$(parse_git_dirty)
|
||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)"
|
||||
if [[ -n $dirty ]]; then
|
||||
prompt_segment yellow black
|
||||
else
|
||||
prompt_segment green black
|
||||
fi
|
||||
echo -n "${ref/refs\/heads\//⭠ }$dirty"
|
||||
fi
|
||||
}
|
||||
|
||||
# Dir: current working directory
|
||||
prompt_dir() {
|
||||
prompt_segment blue black '%~'
|
||||
}
|
||||
|
||||
# Status:
|
||||
# - was there an error
|
||||
# - am I root
|
||||
# - are there background jobs?
|
||||
prompt_status() {
|
||||
local symbols
|
||||
symbols=()
|
||||
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
|
||||
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
|
||||
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
|
||||
|
||||
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
|
||||
}
|
||||
|
||||
## Main prompt
|
||||
build_prompt() {
|
||||
RETVAL=$?
|
||||
prompt_status
|
||||
prompt_context
|
||||
prompt_dir
|
||||
prompt_git
|
||||
prompt_end
|
||||
}
|
||||
|
||||
PROMPT='%{%f%b%k%}$(build_prompt) '
|
||||
Loading…
Add table
Add a link
Reference in a new issue