guest@dotshare [~/groups/shells/zsh] $ ls for-work/ | cat

for work (raw, dl)

needtodropthishere Aug 01, 2019 (shells/zsh)
  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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/zsh

if [[ ! -o interactive ]] then return; fi

zmodload zsh/complist zsh/parameter zsh/regex zsh/zutil 2>/dev/null

# options

options=(
    autoresume         on
    beep               off
    completealiases    on
    completeinword     on
    extendedglob       on
    menucomplete       on
    multios            on
    notify             on
    promptsubst        on
    histignorealldups  on
    histignorespace    on
    histnofunctions    on
    histnostore        on
    histreduceblanks   on
    sharehistory       on
    vi                 on
)

# variables

export \
    FPATH GREP_COLORS PATH \
    BROWSER=/usr/bin/lynx \
    EDITOR=/usr/bin/vim \
    MANPAGER=/usr/bin/less\
    PAGER=/usr/bin/less \
    XAUTHORITY=$HOME/.cache/.Xauthority \
    XDG_CONFIG_HOME=$HOME/.config \
    XDG_DATA_HOME=$HOME/.local/share \
    XDG_CACHE_HOME=$HOME/.cache \
    XDG_DOCUMENTS_DIR=$HOME/files/documents \
    XDG_DOWNLOAD_DIR=$HOME/downloads \
    XDG_MUSIC_DIR=$HOME/files/music \
    XDG_PICTURES_DIR=$HOME/files/pictures \
    XDG_VIDEOS_DIR=$HOME/files/videos

HISTFILE=$XDG_CACHE_HOME/.zsh_history
HISTSIZE=20
LOGCHECK=30
SAVEHIST=0
watch=( notme )

# directories

local \
    name val \
    exclude=( $XDG_RUNTIME_DIR ) \
    script_home=$HOME/scripts/zsh

umask 077

for name in ${(k)parameters}; do
    val=${(P)name:|exclude}

    if [[ ${(L)name} =~ .*(dir|home)$ && -n $val ]] then
        mkdir -p $val
    fi
done

# paths

local -U tmp_path

_path_add() {
    local dir; eval unset $1

    for dir in $tmp_path; do
        if [[ -d $dir ]] then
            eval $1+=$dir
        fi
    done
}

tmp_path=(
    {,/usr{,/local}}{/bin,/sbin}
    $((print - /usr/bin/*_perl(/)) 2>/dev/null)
)
_path_add path

tmp_path=(
    $script_home
    $((print - $script_home/**/*(/)) 2>/dev/null)
    $((print - /usr/share/zsh/**/*(/)) 2>/dev/null)
)
_path_add fpath

tmp_path=( $HOME $XDG_CONFIG_HOME $XDG_DATA_HOME )
_path_add cdpath

unfunction _path_add

# keybindings

if [[ $TERM =~ .*(color|xterm).* ]] then
    bindkey \
        '^[[H'  beginning-of-line \
        '^[[4h' overwrite-mode \
        '^[[P'  delete-char
fi

bindkey \
    '^[[1~' beginning-of-line \
    '^[[2~' overwrite-mode \
    '^[[3~' delete-char \
    '^[[4~' end-of-line \
    '^[[5~' beginning-of-buffer-or-history \
    '^[[6~' end-of-buffer-or-history \
    '^[[A'  up-line-or-history \
    '^[[B'  down-line-or-history \
    '^[[C'  forward-char \
    '^[[D'  backward-char \
    '^?'    backward-delete-char \
    ' '     magic-space \
    '\t'    complete-word

bindkey -M menuselect \
    '^[[2~' vi-insert \
    '^[[5~' backward-word \
    '^[[6~' forward-word \
    '^?'    undo \
    ' '     accept-and-menu-complete \
    '\t'    accept-and-infer-next-history

# scripts

local scripts=( $((print - $script_home/**/*~*.swp~*.zwc(.)) 2>/dev/null) )

for func in $scripts; do
    autoload -U $func
done

_git_prompt() {
    local branch=$((git symbolic-ref --short HEAD) 2>/dev/null)

    if [[ -n $branch ]] then
        local \
            gdir=$((git --rev-parse --git-dir) 2>/dev/null) \
            behind=$((git log --oneline ..@{u} | wc -l | tr -d ' ') 2>/dev/null) \
            ahead=$((git log --oneline @{u}.. | wc -l | tr -d ' ') 2>/dev/null)

        if [[ -r $gdir/MERGE_HEAD ]] then
            RPS1+='%F{5}⚡ '
        fi

        if [[ -n $((git ls-files --other --exclude-standard) 2>/dev/null) ]] then
            RPS1+='%F{1}•'
        fi

        if [[ -n $((git diff | cat) 2>/dev/null) ]] then
            RPS1+='%F{3}•'
        fi

        if [[ -n $((git diff --cached | cat) 2>/dev/null) ]] then
            RPS1+='%F{2}•'
        fi

        RPS1+=" %K{7} %F{3}$branch"

        if (( $behind )) then
            RPS1+="%F{1} -$behind"
        fi

        if (( $ahead )) then
            RPS1+="%F{2} +$ahead"
        fi

        RPS1+=' %f%k'
    fi
}

precmd() {
    local dir=$PWD:t 
    dir=${dir//$USER/\\\$HOME}

    PS1="%F{10}» %f"
    PS2="%F{10}» %f"
    RPS1=''

    if [[ -x /usr/bin/git ]] then
        _git_prompt
    fi

    if [[ $TERM =~ .*(color|xterm).* ]] then
        print -Pn "\e]0;%n@%m:%~\a"
    fi

    print - ''
}

preexec() {
    if [[ $TERM =~ .*(color|xterm).* ]] then
        print -Pn "\e]0;$1\a"
    fi

    if [[ -n @a ]] then
        print - ''
    fi
}

autoload -U \
    run-help \
    compinit && compinit -d $XDG_CACHE_DIR/zsh_comp_dump

# aliases

unalias run-help

aliases=(
    egrep  'egrep --color=auto'
    fgrep  'fgrep --color=auto'
    grep   'grep --color=auto'
    help   'run-help'
    ll     'ls -AFgGhX --group-directories-first --color=auto --time-style=+'
    ls     'ls -AFX --group-directories-first --color=auto'
    pg     "!! | $PAGER"
)

galiases=(
    ...    '../..'
    ....   '../../..'
    xG     '| grep'
    xH     '| head'
    xL     '| less'
    xM     '| more'
    xP     "| $PAGER"
    xT     '| tail'
)

# colors

typeset -TUx LS_COLORS dircolors=(
    {no,fi}'=00;37'
    di'=00;94'
    ex'=00;92'
    ln'=00;97'
    or'=00;91'
    mi'=00;91'
    {pi,so}'=00;93'
    {bd,cd}'=00;95'
    lc'=\e['
)

GREP_COLORS='mt=00;94:fn=00;96:ln=00;33:se=00;90'

# completion

zstyle ':completion:*'                  squeeze-slashes true
zstyle ':completion:*'                  matcher-list \
    '' 'm:{a-z-}={A-Z_}' 'r:|[._-/]=* r:|=*'
zstyle ':completion:*'                  completer \
    _complete _match _ignored

zstyle ':completion:*:*:(cd|kill|ls|mv|rename|rm|vim):*' menu \
    yes select
zstyle ':completion:*:*:(cd|kill|ls|mv|rename|rm|vim):*' force-list \
    always
zstyle ':completion:*:*:(cd|kill|ls|mv|rename|rm|vim):*' ignore-parents \
    parent pwd
zstyle ':completion:*:*:(cd|kill|ls|mv|rename|rm|vim):*' list-dirs-first

zstyle ':completion:*:warnings'         format '%F{9}%d%f'
zstyle ':completion:*:messages'         format '%F{10}%d%f'
zstyle ':completion:*:corrections'      format '%F{11}%d%f'
zstyle ':completion:*:descriptions'     format '%F{12}%d%f'

zstyle ':completion:*:functions'        ignored-patterns '_*'
zstyle ':completion:*:*:*:users'        ignored-patterns \
    'avahi' 'bin' 'colord' 'daemon' 'dbus' 'ftp' 'git' 'http' 'mail' \
    'mpd' 'nobody' 'nvidia*' 'polkitd' '*' 'uuidd'

zstyle ':completion:*'                  list-colors $dircolors 'ma=00;100'
zstyle ':completion:*:*:kill:*'         list-colors "=(#b) #([0-9]#)*=96=91"
zstyle ':completion:*:*:kill:*:jobs'    list-colors "=(#b) #([0-9]#)*=95=91"

zstyle ':completion:*'                  use-cache on
zstyle ':completion:*'                  cache-path \
    "$XDG_CACHE_DIR/zsh_comp_cache"

CLICK TO VIEW

x