guest@dotshare [~/groups/shells/zsh] $ ls Informative-prompt/ | cat

Informative prompt. (scrot, raw, dl)

Serge2702 Jun 27, 2015 (shells/zsh)

SCROT

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
export TERMCMD=urxvtc
export LANG=es_MX.UTF-8
export SUDO_EDITOR=vim 
export EDITOR=vim 
export PACMAN=/usr/bin/powerpill
export STARDICT_DATA_DIR="/home/sergio/.local/share/sdcv/"
export SYSTEMD_LESS=FRXMK
#For tmux in linux
export EVENT_NOEPOLL=1
#================================================================================
#NO EDITAR DESPUÉS DE ESTA LÍNEA
# The following lines were added by compinstall

zstyle ':completion:*' auto-description 'Introduce %d'
zstyle ':completion:*' completer _oldlist _expand _complete _ignored _match _correct _approximate _prefix
zstyle ':completion:*' completions 1
zstyle ':completion:*' condition 0
zstyle ':completion:*' expand prefix
zstyle ':completion:*' file-sort name
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' glob 1
zstyle ':completion:*' group-name ''
zstyle ':completion:*' insert-unambiguous true
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' list-suffixes true
zstyle ':completion:*' matcher-list '' '+m:{[:lower:]}={[:upper:]} m:{[:lower:][:upper:]}={[:upper:][:lower:]}' '+r:|[._-]=* r:|=*'
zstyle ':completion:*' max-errors 2
zstyle ':completion:*' menu select=0
zstyle ':completion:*' original true
zstyle ':completion:*' preserve-prefix '//[^/]##/'
zstyle ':completion:*' prompt 'Found %e errors'
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*' substitute 1
zstyle ':completion:*' verbose true
zstyle :compinstall filename '/home/sergio/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1024
SAVEHIST=1024
setopt appendhistory autocd extendedglob nomatch
unsetopt beep
bindkey -v
# End of lines configured by zsh-newuser-install
#NO EDITAR ANTES DE ESTA LÍNEA
#================================================================================
#Configuración propia:
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
setopt nohashdirs
setopt completealiases
setopt INC_APPEND_HISTORY
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_REDUCE_BLANKS
setopt HIST_VERIFY

alias ls='ls --color=auto --group-directories-first'
alias cp='cp -i'
alias mv='mv -i'
alias grep='grep --color=auto '
alias sbcl="rlwrap -pred -r -s 65536 -m -i -c -D 2 sbcl"
alias rm='rm -I'
alias vi='vim'
alias enable_vbox='sudo modprobe vboxdrv vboxnetadp vboxnetflt vboxpci'
alias disable_vbox='sudo modprobe -r vboxdrv vboxnetadp vboxnetflt vboxpci'
alias speed_test='wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test10.zip'
alias sudo='sudo '
alias mpd_start='systemctl start mpd.service mpdscribble.service --user'
alias mpd_stop='systemctl stop mpd.service mpdscribble.service --user'
alias wifi_on='nmcli radio wifi on'
alias wifi_off='nmcli radio wifi off'

function ranger-cd {
    tempfile='/tmp/chosendir'
    /usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}"
    test -f "$tempfile" &&
    if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
        cd -- "$(cat "$tempfile")"
    fi
    rm -f -- "$tempfile"
}

typeset -A key

key[Home]=${terminfo[khome]}
key[End]=${terminfo[kend]}
key[Insert]=${terminfo[kich1]}
key[Delete]=${terminfo[kdch1]}
key[Up]=${terminfo[kcuu1]}
key[Down]=${terminfo[kcud1]}
key[Left]=${terminfo[kcub1]}
key[Right]=${terminfo[kcuf1]}
key[PageUp]=${terminfo[kpp]}
key[PageDown]=${terminfo[knp]}

# setup key accordingly
[[ -n "${key[Home]}"     ]]  && bindkey  "${key[Home]}"     beginning-of-line
[[ -n "${key[End]}"      ]]  && bindkey  "${key[End]}"      end-of-line
[[ -n "${key[Insert]}"   ]]  && bindkey  "${key[Insert]}"   overwrite-mode
[[ -n "${key[Delete]}"   ]]  && bindkey  "${key[Delete]}"   delete-char
[[ -n "${key[Left]}"     ]]  && bindkey  "${key[Left]}"     backward-char
[[ -n "${key[Right]}"    ]]  && bindkey  "${key[Right]}"    forward-char
[[ -n "${key[PageUp]}"   ]]  && bindkey  "${key[PageUp]}"   beginning-of-buffer-or-history
[[ -n "${key[PageDown]}" ]]  && bindkey  "${key[PageDown]}" end-of-buffer-or-history
[[ -n "${key[Up]}"   ]]  && bindkey  "${key[Up]}"    history-beginning-search-backward
[[ -n "${key[Down]}" ]]  && bindkey  "${key[Down]}"  history-beginning-search-forward

# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo 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

setopt prompt_subst
autoload -U colors && colors

function calcula_ancho {
    temp=" ${USER} _ ${HOST} _  _"
    dir_actual=$PWD

    if [[ "$dir_actual[0,${#HOME}]" == "$HOME" ]]
    then
        dir_actual="~$dir_actual[$((${#HOME}+1)),-1]"
    fi

    let restante=${COLUMNS}-${#temp}
    longitud_dir=${#dir_actual}
    if [[ "$longitud_dir" -gt "$restante" ]]
    then
        dir_actual="...${dir_actual:$(($longitud_dir-$restante+3))}"
    fi
}

function nivel_ranger {
if [ -z "$RANGER_LEVEL" ]
then
    string_nivel=""
else
    string_nivel=" ranger │"
fi

}

reload () {
    exec "${SHELL}" "$@"
}

case $TERM in
    termite|*xterm*|rxvt|rxvt-unicode|rxvt-256color|rxvt-unicode-256color|(dt|k|E)term)
        separador1=separador2=separador3=
        precmd () {
            print -Pn "\e]0;%n@%M: %1~ \a"
            calcula_ancho
            tmux_sessions
        } 
        preexec () { 
            print -Pn "\e]0;%n@%M %1~ ($1)\a" 
        }
        ;;
    screen|screen-256color)
        separador1=separador2=separador3=
        precmd () { 
            print -Pn "\e]83;title \"$1\"\a" 
            print -Pn "\e]0;TMUX - %n@%M %1~\a" 
            calcula_ancho
            tmux_sessions
        }
        preexec () { 
            print -Pn "\e]83;title \"$1\"\a" 
            print -Pn "\e]0;TMUX - %n@%M %# %1~ ($1)\a" 
        }
        ;; 
    *)
        separador1=separador2=separador3=▒
        precmd () {
            calcula_ancho
            tmux_sessions
        } 
        ;;
esac

over_ssh() {
    if [ -n "${SSH_CLIENT}" ]; then
        return 0
    else
        return 1
    fi
}

if over_ssh; then
    prompt_is_ssh="%{%K{green}%B%F{white}%} SSH %{%b%K{cyan}%F{green}%}"
else
    prompt_is_ssh="%{%b%K{cyan}%F{green}%}"
fi

if [ -n "${RANGER_LEVEL}" ]
then
    nivel_ranger="%{%K{cyan}%B%F{white}%} ranger %{%b%K{magenta}%F{cyan}%}"
else
    nivel_ranger="%{%K{magenta}%F{cyan}%}"
fi

tmux_sessions(){
    if $(tmux info &> /dev/null) 
    then 
        numero_tmux="%{%K{magenta}%B%F{white}%} tmux: $(tmux ls | wc -l) %{%b%K{red}%F{magenta}%}"
    else
        numero_tmux="%{%b%K{red}%F{magenta}%}"
    fi
}

PROMPT='%{%B%K{blue}%15F%} %n %{%b%K{green}%F{blue}%}$separador1%{%B%15F%} %m %{%b%K{red}%F{green}%}$separador1%{%B%15F%} $dir_actual %{%b%k%F{red}%}$separador1
$prompt_is_ssh$separador1$nivel_ranger$separador1$numero_tmux$separador1%{%K{red}%B%F{white}%} %#%(0?,, %{%b%K{red}%15F%}$separador2 %{%B%F{white}%}%?) %{%b%k%F{red}%}$separador1%{%b%k$reset_color%} '

RPROMPT='%{%F{red}%}$separador3%{%B%K{red}%F{white}%} %* %{%b%F{red}%}$separador1%{$reset_color%}'

autoload -U   edit-command-line
zle -N        edit-command-line
bindkey -M vicmd 'v' edit-command-line

setopt interactivecomments

CLICK TO VIEW

x

Notes

I find this prompt very useful. It has the following features:

  • It informs you if you are logged in via ssh.
  • It informs you if you are currently in a shell inside ranger.
  • It tells you the number of active tmux sessions.
  • Outputs the exit condition of the last command if it wasn’t zero.
  • Outputs if you are root or just a normal user.
  • Trims the current path if it is wider than the terminal width.

I used several ideas that I found in the Arch Wiki.