summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/aliases.zsh25
-rw-r--r--lib/bzr.zsh10
-rw-r--r--lib/correction.zsh23
-rw-r--r--lib/edit-command-line.zsh3
-rw-r--r--lib/functions.zsh58
-rw-r--r--lib/git.zsh8
-rw-r--r--lib/key-bindings.zsh76
-rw-r--r--lib/nvm.zsh9
-rw-r--r--lib/prompt_info_functions.zsh33
-rw-r--r--lib/rbenv.zsh2
-rw-r--r--lib/rvm.zsh8
-rw-r--r--lib/spectrum.zsh7
-rw-r--r--lib/termsupport.zsh5
-rw-r--r--lib/theme-and-appearance.zsh4
14 files changed, 204 insertions, 67 deletions
diff --git a/lib/aliases.zsh b/lib/aliases.zsh
index 9b3709172..2094f60a0 100644
--- a/lib/aliases.zsh
+++ b/lib/aliases.zsh
@@ -6,6 +6,11 @@ alias po='popd'
alias ...='cd ../..'
alias -- -='cd -'
+# Prevent headaches
+alias cp='cp -v'
+alias rm='rm -v'
+alias mv='mv -v'
+
# Super user
alias _='sudo'
alias please='sudo'
@@ -13,13 +18,23 @@ alias please='sudo'
#alias g='grep -in'
# Show history
-alias history='fc -l 1'
-
+if [ "$HIST_STAMPS" = "mm/dd/yyyy" ]
+then
+ alias history='fc -fl 1'
+elif [ "$HIST_STAMPS" = "dd.mm.yyyy" ]
+then
+ alias history='fc -El 1'
+elif [ "$HIST_STAMPS" = "yyyy-mm-dd" ]
+then
+ alias history='fc -il 1'
+else
+ alias history='fc -l 1'
+fi
# List direcory contents
alias lsa='ls -lah'
-alias l='ls -la'
-alias ll='ls -l'
-alias la='ls -lA'
+alias l='ls -lah'
+alias ll='ls -lh'
+alias la='ls -lAh'
alias sl=ls # often screw this up
alias afind='ack-grep -il'
diff --git a/lib/bzr.zsh b/lib/bzr.zsh
new file mode 100644
index 000000000..005a16500
--- /dev/null
+++ b/lib/bzr.zsh
@@ -0,0 +1,10 @@
+## Bazaar integration
+## Just works with the GIT integration just add $(bzr_prompt_info) to the PROMPT
+function bzr_prompt_info() {
+ BZR_CB=`bzr nick 2> /dev/null | grep -v "ERROR" | cut -d ":" -f2 | awk -F / '{print "bzr::"$1}'`
+ if [ -n "$BZR_CB" ]; then
+ BZR_DIRTY=""
+ [[ -n `bzr status` ]] && BZR_DIRTY=" %{$fg[red]%} * %{$fg[green]%}"
+ echo "$ZSH_THEME_SCM_PROMPT_PREFIX$BZR_CB$BZR_DIRTY$ZSH_THEME_GIT_PROMPT_SUFFIX"
+ fi
+} \ No newline at end of file
diff --git a/lib/correction.zsh b/lib/correction.zsh
index 436446101..47eb83b1d 100644
--- a/lib/correction.zsh
+++ b/lib/correction.zsh
@@ -1,14 +1,13 @@
-if [[ "$DISABLE_CORRECTION" == "true" ]]; then
- return
-else
+alias man='nocorrect man'
+alias mv='nocorrect mv'
+alias mysql='nocorrect mysql'
+alias mkdir='nocorrect mkdir'
+alias gist='nocorrect gist'
+alias heroku='nocorrect heroku'
+alias ebuild='nocorrect ebuild'
+alias hpodder='nocorrect hpodder'
+alias sudo='nocorrect sudo'
+
+if [[ "$ENABLE_CORRECTION" == "true" ]]; then
setopt correct_all
- alias man='nocorrect man'
- alias mv='nocorrect mv'
- alias mysql='nocorrect mysql'
- alias mkdir='nocorrect mkdir'
- alias gist='nocorrect gist'
- alias heroku='nocorrect heroku'
- alias ebuild='nocorrect ebuild'
- alias hpodder='nocorrect hpodder'
- alias sudo='nocorrect sudo'
fi
diff --git a/lib/edit-command-line.zsh b/lib/edit-command-line.zsh
deleted file mode 100644
index db2000325..000000000
--- a/lib/edit-command-line.zsh
+++ /dev/null
@@ -1,3 +0,0 @@
-autoload -U edit-command-line
-zle -N edit-command-line
-bindkey '\C-x\C-e' edit-command-line
diff --git a/lib/functions.zsh b/lib/functions.zsh
index 63ab755cf..aaf8a03e3 100644
--- a/lib/functions.zsh
+++ b/lib/functions.zsh
@@ -15,3 +15,61 @@ function take() {
cd $1
}
+#
+# Get the value of an alias.
+#
+# Arguments:
+# 1. alias - The alias to get its value from
+# STDOUT:
+# The value of alias $1 (if it has one).
+# Return value:
+# 0 if the alias was found,
+# 1 if it does not exist
+#
+function alias_value() {
+ alias "$1" | sed "s/^$1='\(.*\)'$/\1/"
+ test $(alias "$1")
+}
+
+#
+# Try to get the value of an alias,
+# otherwise return the input.
+#
+# Arguments:
+# 1. alias - The alias to get its value from
+# STDOUT:
+# The value of alias $1, or $1 if there is no alias $1.
+# Return value:
+# Always 0
+#
+function try_alias_value() {
+ alias_value "$1" || echo "$1"
+}
+
+#
+# Set variable "$1" to default value "$2" if "$1" is not yet defined.
+#
+# Arguments:
+# 1. name - The variable to set
+# 2. val - The default value
+# Return value:
+# 0 if the variable exists, 3 if it was set
+#
+function default() {
+ test `typeset +m "$1"` && return 0
+ typeset -g "$1"="$2" && return 3
+}
+
+#
+# Set enviroment variable "$1" to default value "$2" if "$1" is not yet defined.
+#
+# Arguments:
+# 1. name - The env variable to set
+# 2. val - The default value
+# Return value:
+# 0 if the env variable exists, 3 if it was set
+#
+function env_default() {
+ env | grep -q "^$1=" && return 0
+ export "$1=$2" && return 3
+}
diff --git a/lib/git.zsh b/lib/git.zsh
index df0fcedbb..305a77aff 100644
--- a/lib/git.zsh
+++ b/lib/git.zsh
@@ -1,8 +1,10 @@
# get the name of the branch we are on
function git_prompt_info() {
- ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
- ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
- echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
+ if [[ "$(git config --get oh-my-zsh.hide-status)" != "1" ]]; then
+ ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
+ ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
+ echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
+ fi
}
diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh
index 5f499f3e8..94f1842f3 100644
--- a/lib/key-bindings.zsh
+++ b/lib/key-bindings.zsh
@@ -1,34 +1,48 @@
-# TODO: Explain what some of this does..
-
-bindkey -e
-bindkey '\ew' kill-region
-bindkey -s '\el' "ls\n"
-bindkey '^r' history-incremental-search-backward
-bindkey "^[[5~" up-line-or-history
-bindkey "^[[6~" down-line-or-history
-
-# make search up and down work, so partially type and hit up/down to find relevant stuff
-bindkey '^[[A' up-line-or-search
-bindkey '^[[B' down-line-or-search
-
-bindkey "^[[H" beginning-of-line
-bindkey "^[[1~" beginning-of-line
-bindkey "^[OH" beginning-of-line
-bindkey "^[[F" end-of-line
-bindkey "^[[4~" end-of-line
-bindkey "^[OF" end-of-line
-bindkey ' ' magic-space # also do history expansion on space
-
-bindkey "^[[1;5C" forward-word
-bindkey "^[[1;5D" backward-word
-
-bindkey '^[[Z' reverse-menu-complete
-
-# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~
-bindkey '^?' backward-delete-char
-bindkey "^[[3~" delete-char
-bindkey "^[3;5~" delete-char
-bindkey "\e[3~" delete-char
+# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html
+# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins
+# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets
+
+# Make sure that the terminal is in application mode when zle is active, since
+# only then values from $terminfo are valid
+if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
+ function zle-line-init() {
+ echoti smkx
+ }
+ function zle-line-finish() {
+ echoti rmkx
+ }
+ zle -N zle-line-init
+ zle -N zle-line-finish
+fi
+
+bindkey -e # Use emacs key bindings
+
+bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark
+bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls
+bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line.
+bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history
+bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history
+
+bindkey "${terminfo[kcuu1]}" up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward
+bindkey "${terminfo[kcud1]}" down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward
+
+bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line
+bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line
+
+bindkey ' ' magic-space # [Space] - do history expansion
+
+bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word
+bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word
+
+bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards
+
+bindkey '^?' backward-delete-char # [Backspace] - delete backward
+bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward
+
+# Edit the current command line in $EDITOR
+autoload -U edit-command-line
+zle -N edit-command-line
+bindkey '\C-x\C-e' edit-command-line
# consider emacs keybindings:
diff --git a/lib/nvm.zsh b/lib/nvm.zsh
new file mode 100644
index 000000000..5cadf7061
--- /dev/null
+++ b/lib/nvm.zsh
@@ -0,0 +1,9 @@
+# get the node.js version
+function nvm_prompt_info() {
+ [ -f $HOME/.nvm/nvm.sh ] || return
+ local nvm_prompt
+ nvm_prompt=$(node -v 2>/dev/null)
+ [[ "${nvm_prompt}x" == "x" ]] && return
+ nvm_prompt=${nvm_prompt:1}
+ echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt}${ZSH_THEME_NVM_PROMPT_SUFFIX}"
+}
diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh
new file mode 100644
index 000000000..335c02a3d
--- /dev/null
+++ b/lib/prompt_info_functions.zsh
@@ -0,0 +1,33 @@
+# *_prompt_info functions for usage in your prompt
+#
+# Plugin creators, please add your *_prompt_info function to the list
+# of dummy implementations to help theme creators not receiving errors
+# without the need of implementing conditional clauses.
+#
+# See also lib/bzr.zsh, lib/git.zsh and lib/nvm.zsh for
+# git_prompt_info, bzr_prompt_info and nvm_prompt_info
+
+# Dummy implementations that return false to prevent command_not_found
+# errors with themes, that implement these functions
+# Real implementations will be used when the respective plugins are loaded
+function chruby_prompt_info hg_prompt_info pyenv_prompt_info \
+ rbenv_prompt_info svn_prompt_info vi_mode_prompt_info \
+ virtualenv_prompt_info {
+ return 1
+}
+
+# oh-my-zsh supports an rvm prompt by default
+# get the name of the rvm ruby version
+function rvm_prompt_info() {
+ [ -f $HOME/.rvm/bin/rvm-prompt ] || return 1
+ local rvm_prompt
+ rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${=ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null)
+ [[ "${rvm_prompt}x" == "x" ]] && return 1
+ echo "${ZSH_THEME_RVM_PROMPT_PREFIX:=(}${rvm_prompt}${ZSH_THEME_RVM_PROMPT_SUFFIX:=)}"
+}
+
+# use this to enable users to see their ruby version, no matter which
+# version management system they use
+function ruby_prompt_info() {
+ echo $(rvm_prompt_info || rbenv_prompt_info || chruby_prompt_info)
+}
diff --git a/lib/rbenv.zsh b/lib/rbenv.zsh
deleted file mode 100644
index a8b6c323c..000000000
--- a/lib/rbenv.zsh
+++ /dev/null
@@ -1,2 +0,0 @@
-# using the rbenv plugin will override this with a real implementation
-function rbenv_prompt_info() {}
diff --git a/lib/rvm.zsh b/lib/rvm.zsh
deleted file mode 100644
index e8744e61e..000000000
--- a/lib/rvm.zsh
+++ /dev/null
@@ -1,8 +0,0 @@
-# get the name of the ruby version
-function rvm_prompt_info() {
- [ -f $HOME/.rvm/bin/rvm-prompt ] || return
- local rvm_prompt
- rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null)
- [[ "${rvm_prompt}x" == "x" ]] && return
- echo "${ZSH_THEME_RVM_PROMPT_PREFIX:=(}${rvm_prompt}${ZSH_THEME_RVM_PROMPT_SUFFIX:=)}"
-}
diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh
index 2fdf537ef..166c942fb 100644
--- a/lib/spectrum.zsh
+++ b/lib/spectrum.zsh
@@ -26,3 +26,10 @@ function spectrum_ls() {
done
}
+# Show all 256 colors where the background is set to specific color
+function spectrum_bls() {
+ for code in {000..255}; do
+ ((cc = code + 1))
+ print -P -- "$BG[$code]$code: Test %{$reset_color%}"
+ done
+}
diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
index 80319e1a8..5f2fe63d4 100644
--- a/lib/termsupport.zsh
+++ b/lib/termsupport.zsh
@@ -27,9 +27,8 @@ function omz_termsupport_preexec {
emulate -L zsh
setopt extended_glob
local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
- local LINE="${2:gs/$/\\$}"
- LINE="${LINE:gs/%/%%}"
- title "$CMD" "%100>...>$LINE%<<"
+ local LINE="${2:gs/%/%%}"
+ title '$CMD' '%100>...>$LINE%<<'
}
autoload -U add-zsh-hook
diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh
index 2677615c0..0353f9db4 100644
--- a/lib/theme-and-appearance.zsh
+++ b/lib/theme-and-appearance.zsh
@@ -11,6 +11,10 @@ then
# On NetBSD, test if "gls" (GNU ls) is installed (this one supports colors);
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
gls --color -d . &>/dev/null 2>&1 && alias ls='gls --color=tty'
+ elif [[ "$(uname -s)" == "OpenBSD" ]]; then
+ # On OpenBSD, test if "colorls" is installed (this one supports colors);
+ # otherwise, leave ls as is, because OpenBSD's ls doesn't support -G
+ colorls -G -d . &>/dev/null 2>&1 && alias ls='colorls -G'
else
ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G'
fi