]> git.netwichtig.de Git - user/henk/vcsh/zsh.git/blob - .zsh_functions
Added vi-mode bindings and set default to vi-mode.
[user/henk/vcsh/zsh.git] / .zsh_functions
1 function info_print () {
2     local esc_begin esc_end
3     esc_begin="$1"
4     esc_end="$2"
5     shift 2
6     printf '%s' ${esc_begin}
7     printf '%s' "$*"
8     printf '%s' "${esc_end}"
9 }
10
11 function set_title () {
12     info_print  $'\e]0;' $'\a' "$@"
13 }
14
15 function ESC_print () {
16     info_print $'\ek' $'\e\\' "$@"
17 }
18
19 preexec () {
20     case $TERM in
21         (xterm*|rxvt*)
22             set_title "${(%):-"%n@%m:"}" "$1"
23         ;;
24         (screen*)
25             local CMD=${1[(wr)^(*=*|sudo|ssh|evince|-*)]}
26             ESC_print ${CMD}
27         ;;
28     esac
29 }
30
31 precmd () {
32     case $TERM in
33         (xterm*|rxvt*)
34             set_title ${(%):-"%n@%m: %~"}
35         ;;
36         (screen*)
37             ESC_print "zsh"
38         ;;
39     esac
40
41     vcs_info
42     if [[ -n ${vcs_info_msg_0_} ]]; then
43         local HENKSPROMPT="%(0?..%F{red}E%?%f )%(1j.%F{yellow}J%j%f .)%(3L.%F{yellow}L%L%f .)%3~ %F{green}$VCSH_REPO_NAME%f%F{yellow}${vcs_info_msg_0_}%f%# "
44         PS1="$HENKSPROMPTHEADER$HENKSPROMPT"
45     else
46         local HENKSPROMPT="%(0?..%F{red}E%?%f )%(1j.%F{yellow}J%j%f .)%(3L.%F{yellow}L%L%f .)%3~ %F{green}$VCSH_REPO_NAME%f%# "
47         PS1="$HENKSPROMPTHEADER$HENKSPROMPT"
48     fi
49 }
50
51 function vifind () {
52     vi $( find $1 -type f )
53 }
54
55 function shufflevideos () {
56     find $@ -type f -iregex ".*\.\(avi\|flv\|mkv\|mpeg\|mpg\|wmv\|wva\|mp4\|webm\|wva\|m4v\|ogm\|mp4\|mov\)" -exec mpv --shuffle $MPVOPTS \{\} +
57 }
58
59 function zle-line-init zle-keymap-select {
60     RPS1="%B${${KEYMAP/vicmd/c}/(main|viins)/}%b"
61     RPS2=$RPS1
62     zle reset-prompt
63 }