-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.zshrc
1699 lines (1407 loc) · 39 KB
/
.zshrc
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
. ~/bin/environment-variables
export TERM=alacritty
export DISABLE_MAGIC_FUNCTIONS=true
export KEYTIMEOUT=100
export WORDCHARS=-
# :prezto
{
zstyle ':prezto:*:*' color 'yes'
zstyle ':prezto:load' pmodule \
'helper' \
'environment' \
'terminal' \
'history' \
'directory' \
'completion' \
'git'
zstyle ':prezto:module:editor' key-bindings 'vi'
zstyle ':completion:*' rehash true
}
#docompinit() {
# compinit -C
#}
# :zle
{
zle() {
if [[ "$1" == "-R" || "$1" == "-U" ]]; then
unset -f zle
#docompinit
:plugins:load
:compdef:load
fi
builtin zle "${@}"
}
}
# :zgen
{
if [ ! -d ~/.zgenom ]; then
git clone https://github.com/jandamm/zgenom ~/.zgenom
fi
if [ ! -d ~/.zpezto ]; then
ln -sfT ~/.zgenom/sorin-ionescu/prezto-master ~/.zprezto
fi
AUTOPAIR_INHIBIT_INIT=1
source ~/.zgenom/zgenom.zsh
#docompinit
if ! zgenom saved; then
zgenom load seletskiy/zsh-zgen-compinit-tweak
zgenom load sorin-ionescu/prezto
zgenom load seletskiy/zsh-prompt-lambda17
zgenom load mafredri/zsh-async
if [[ ! -e ~/.zgen/deadcrew/deadfiles-master ]]; then
mkdir -p ~/.zgen/deadcrew/
ln -s ~/deadfiles ~/.zgen/deadcrew/deadfiles-master
fi
zgenom load deadcrew/deadfiles
zgenom compile ~/.zshrc
zgenom save
fi
}
{
:plugins:load() {
zgenom load kovetskiy/zsh-quotes
zgenom load kovetskiy/zsh-add-params
zgenom load zsh-users/zsh-completions
#zgenom load seletskiy/zsh-ssh-urxvt
zgenom load seletskiy/zsh-hash-aliases
zgenom load seletskiy/zsh-smart-kill-word
zgenom load hlissner/zsh-autopair autopair.zsh
zgenom load seletskiy/zsh-fuzzy-search-and-edit
zgenom load kovetskiy/zsh-alias-search
zgenom oh-my-zsh plugins/sudo
zgenom load zdharma/fast-syntax-highlighting
zgenom load zsh-users/zsh-history-substring-search
zgenom load seletskiy/zsh-hijack
ZSH_AUTOSUGGEST_STRATEGY=("history")
zgenom load zsh-users/zsh-autosuggestions && _zsh_autosuggest_start
export NVM_LAZY_LOAD=true
zgenom load lukechilds/zsh-nvm
hash-aliases:install
autopair-init
:bind-history
}
}
{
:compdef:load() {
compdef :process:kill=pkill
compdef github-browse=ls
compdef man-directive=man
compdef vim-which=which
compdef guess=which
compdef _git gdd=git-checkout
}
}
{
if [[ "$BACKGROUND" == "light" ]]; then
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=9"
fi
}
{
unalias -a
unsetopt cdablevars
unsetopt noclobber
unsetopt correct
unsetopt correct_all
unsetopt interactivecomments
setopt rcquotes
}
# :binds
{
# https://github.com/zsh-users/zsh-syntax-highlighting/issues/411
:bind-history() {
bindkey -v "^R" fzf-history-widget
bindkey -v "^P" fzf-file-widget
bindkey -v "^[[A" history-substring-search-up
bindkey -v "^[[B" history-substring-search-down
}
bindkey -a '^[' vi-insert
#bindkey -v "^A" beginning-of-line
bindkey "^[[1~" beginning-of-line
bindkey "^[[7~" beginning-of-line
#bindkey -v "^P" end-of-line
bindkey "^[[4~" end-of-line
bindkey "^[[8~" end-of-line
bindkey -v "^A" push-line
bindkey -v '^?' backward-delete-char
bindkey -v '^H' backward-delete-char
bindkey -v '^[[3~' delete-char
bindkey -v '^B' backward-word
bindkey -v '^E' forward-word
bindkey -v "^L" clear-screen
bindkey -v '^K' add-params
bindkey -v '^O' toggle-quotes
bindkey '^W' smart-backward-kill-word
bindkey '^F' smart-forward-kill-word
bindkey "^S" sudo-command-line
bindkey "^F" alias-search
bindkey "^F" alias-search
exit_zsh() { exit }
zle -N exit_zsh
bindkey '^D' exit_zsh
}
# :setup
{
autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
autoload -U add-zsh-hook
autoload -Uz promptinit
promptinit
prompt lambda17
:prompt-pwd() {
if [[ "$PWD" == "$HOME" || "$PWD" == "$HOME/" ]]; then
lambda17:print ''
return
fi
zsh-prompt
}
zstyle -d "lambda17:00-main" transform
zstyle -d "lambda17>00-tty>00-root>00-main>00-status>00-banner" 01-git-stash
zstyle -d "lambda17:20-git" transform
zstyle -d "lambda17:25-head" when
zstyle -d "lambda17:91-exit-code" fg
zstyle -d "lambda17:91-exit-code" text
zstyle -d "lambda17:91-exit-code" when
zstyle -d "lambda17::async" pre-draw
zstyle "lambda17:00-banner" right " "
zstyle "lambda17:01-git-stash" fg "black"
zstyle "lambda17:05-sign" text "ƛ"
zstyle "lambda17:09-arrow" transition ""
zstyle "lambda17:15-pwd" text '$(:prompt-pwd)'
zstyle "lambda17:20-git" left " "
zstyle "lambda17:25-head" fg-branch "green"
zstyle "lambda17:25-head" fg-detached "red"
zstyle "lambda17:25-head" fg-empty "blue"
zstyle "lambda17:25-head" fg-tag "yellow"
zstyle "lambda17:26-git-clean" fg "green"
zstyle "lambda17:26-git-dirty" fg "red"
zstyle "lambda17:26-git-dirty" text "↕"
:lambda17:read-terminal-background () {
:
}
if [[ "${PROFILE}" == "laptop" ]]; then
zstyle "lambda17:00-banner" bg 'black'
zstyle "lambda17:05-sign" fg 'white'
else
zstyle "lambda17:00-banner" bg 'white'
zstyle "lambda17:05-sign" fg 'black'
fi
autoload -U colors
colors
setopt prompt_sp
PROMPT_EOL_MARK=''
setopt autocd
setopt auto_name_dirs
setopt auto_pushd
setopt pushd_ignore_dups
setopt rmstarsilent
setopt append_history
setopt extended_history
setopt hist_ignore_space
setopt hist_verify
setopt inc_append_history
setopt share_history
setopt hist_save_by_copy
# If the internal history needs to be trimmed to add the current command line,
# setting this option will cause the oldest history event that has a duplicate
# to be lost before losing a unique event from the list. You should be sure to
# set the value of HISTSIZE to a larger number than SAVEHIST in order to give
# you some room for the duplicated events, otherwise this option will behave
# just like HIST_IGNORE_ALL_DUPS once the history fills up with unique events.
#
# ^disabled
unsetopt histexpiredupsfirst
# If a new command line being added to the history list duplicates an older
# one, the older command is removed from the list (even if it is not the
# previous event).
#
# ^disabled
unsetopt histignorealldups
# Do not enter command lines into the history list if they are duplicates of the
# previous event.
#
# ^ enabled
setopt hist_ignore_dups
unsetopt hist_save_no_dups
zstyle ':zle:smart-kill-word' precise always
zstyle ':zle:smart-kill-word' keep-slash true
}
# :hash
{
hash -d dotfiles=~/dotfiles/
hash -d deadfiles=~/deadfiles/
hash -d src=~/sources/
}
# :fastcd
{
bindkey -v '^N' :favor
zle -N :favor
:favor() {
local favor_dir="$(favor --quiet)"
if [[ ! "$favor_dir" ]]; then
return
fi
eval cd "$favor_dir"
unset favor_dir
#clear
zle -R
lambda17:update
zle reset-prompt
}
bindkey -v '^Q' :fzf:git:file:vim
zle -N :fzf:git:file:vim
:fzf:git:file:vim() {
local __target="$(fzf-git-file)"
if [[ ! "$__target" ]]; then
return
fi
__target=$(grep -Po "$(pwd)/\K.*" <<< "$__target")
BUFFER="vim $__target"
zle accept-line -w
}
}
# :func
{
packages-add() {
echo $@ >> ~/sources/dotfiles/packages
}
man-find() {
man --regex -wK "$@" \
| sed 's#.*/##g' \
| cut -d. -f1 \
| uniq
}
man-directive() {
man $1 | less +"/^\s{7}$2\s"
}
sed-replace() {
local from=$(sed 's@/@\\/@g' <<< "$1")
shift
local to=""
if [ $# -ne 0 ]; then
to=$(sed 's@/@\\/@g' <<< "$1")
shift
fi
if [ $# -ne 0 ]; then
local diff=false
local files=()
for file in $@; do
if [ "$file" = "!" ]; then
diff=true
else
files+=("$file")
fi
done
for file in "${files[@]}"; do
if $diff; then
after=$(mktemp -u)
sed -r "s/$from/$to/" $file > $after
git diff $file $after
else
sed -ri "s/$from/$to/" $file
fi
done
else
sed -r "s/$from/$to/"
fi
}
cut-d-t() {
local d="$1"
shift
cut -d"$d" -f"$@"
}
:find() {
ag -f -l -U -g "$*" --nocolor
}
xargs-eval() {
local pass_stdin=false
if [ "$1" = "-" ]; then
pass_stdin=true
shift
fi
local cmd="$(sed 's/@/"@"/g' <<< $@)"
local line="{ $cmd ; }"
if $pass_stdin; then
line="$line <<< '@'"
fi
local main_input="$(cat)"
xargs -n1 -I@ echo "$line" <<< "$main_input" \
| while read subcmd; do
eval "(${subcmd[@]})" </dev/tty
done
}
cd-and-ls() {
cd $@ && ls -lah --color=always
}
git-clone-github() {
local uri="$1"
local dir="$2"
local user=$(cut -d/ -f1 <<< "$uri")
local project=$(cut -d/ -f2 <<< "$uri")
if ! grep -q "/" <<< "$uri"; then
project="$user"
user="kovetskiy"
fi
if [[ "$user" = "s" ]]; then
user="seletskiy"
fi
if [[ "$user" = "r" ]]; then
user="reconquest"
fi
if [[ "$user" = "k" ]]; then
user="kovetskiy"
fi
uri="https://github.com/$user/$project"
echo "$uri"
git clone "$uri" $dir
}
git-checkout-orphan() {
git checkout --orphan "$1"
git status -s | awk '{print $2}' | xargs -n1 rm -rf
git add .
}
git-create-and-commit-empty-gitignore() {
gcor $1
touch .gitignore
git add .gitignore
git commit -m ".gitignore added"
}
alias-grep() {
local query="$*"
if declare -f "$query" 2>/dev/null; then
return
fi
alias | grep -F -- "$*"
}
git-remote-set-origin-me() {
if ! git remote | grep -q upstream; then
git remote rename origin upstream
fi
local new_url=$(
git remote show -n upstream \
| awk '/Fetch URL:/{print $3}' \
| sed-replace '([:/])([a-zA-Z0-9_-]+)/(\w+)' '\1me/\3'
)
git remote rm origin
echo "$new_url"
git remote add origin "$new_url"
}
create-and-change-directory() {
mkdir -p "$@"
cd "$@"
}
aur-create-project() {
local package="$1"
if [[ "$package" == "" || "$package" == "-h" ]]; then
echo "aur-create-project <package> [<file>]..."
return
fi
local dir=$(mktemp -d --suffix=$package)
local url="ssh://[email protected]/$package.git"
git clone $url $dir
if [[ $# -gt 1 ]]; then
while shift &>/dev/null; do
cp -r $1 $dir/
done
fi
cd $dir
}
aur-import-project-golang() {
local package="$1"
local desc="$2"
local git="$3"
if [[ "$package" == "" || "$package" == "-h" ]]; then
echo "aur-import-project-golang <package> <description> <url>"
return
fi
local dir=$(mktemp -d --suffix=$package)
local url="ssh://[email protected]/$package.git"
git clone $url $dir
cd $dir
git=$(sed-replace 'https?://' 'git://' <<< "$git")
go-makepkg -n "$package" -d . -c "$desc" "$git"
mksrcinfo
git add PKGBUILD .SRCINFO
}
aur-clone() {
local package=$1
:sources:get "ssh://[email protected]/$package.git"
}
cd-pkgbuild() {
local dir=$(basename "$(pwd)")
if grep -q '\-pkgbuild' <<< "$dir"; then
cd ../$(sed -r 's/\-pkgbuild//g' <<< "$dir")
return
fi
local dir_pkgbuild="${dir}-pkgbuild"
if [ -d "../$dir_pkgbuild" ]; then
cd "../$dir_pkgbuild"
return
fi
cp -r "../$dir" "../$dir_pkgbuild"
cd "../$dir_pkgbuild"
if [ "$(git rev-parse --abbrev-parse HEAD)" = "pkgbuild" ]; then
return
fi
git fetch
if git branch -a | grep -q pkgbuild; then
git stash
git checkout pkgbuild
git-clean-powered
return
fi
git-checkout-orphan pkgbuild
}
go-makepkg-enhanced() {
if [[ "$1" = "-h" || $# == 0 ]]; then
echo "<package> <description> [repo]" >&2
return 1
fi
local package="$1"
mkdir -p /tmp/go-makepkg-$package/
cd /tmp/go-makepkg-$package/
local description="$2"
local repo="$3"
shift 2
if [ "$repo" ]; then
shift
else
repo=$(git remote get-url origin)
fi
if grep -q "github.com" <<< "$repo"; then
repo=$(sed-replace '.*@' 'git://' <<< "$repo")
repo=$(sed-replace '.*://' 'git://' <<< "$repo")
fi
go-makepkg -g -c -n "$package" -d . $(echo $FLAGS) "$description" "$repo" $@
}
copy-to-clipboard() {
if [ $# -ne 0 ]; then
if [ -e "$1" ]; then
xclip -selection clipboard < "$1"
xclip -selection primary < "$1"
else
xclip -selection clipboard <<< "$@"
xclip -selection primary <<< "$@"
fi
else
xclip -selection clipboard
xclip -selection primary
fi
}
restore-pkgver-pkgrel() {
sed-replace 'pkgver=.*' 'pkgver=${PKGVER:-autogenerated}' ${1:-PKGBUILD}
sed-replace 'pkgrel=.*' 'pkgrel=${PKGREL:-1}' ${1:-PKGBUILD}
}
migrate-to-deadfiles() {
(
local dotfiles=~/dotfiles
local deadfiles=~/deadfiles
for file in $@; do
mv $dotfiles/$file $deadfiles/$file
done
cd $deadfiles
git add .
git commit -m "$@ migrated from kovetskiy/dotfiles"
git push origin master || return 1
#git stash pop
cd $dotfiles
git add .
git commit -m "$@ migrated to deadcrew/deadfiles"
git push origin master || return 1
#git stash pop
)
}
github-browse() {
local file="$1"
local line="${2:+#L$2}"
hub browse -u -- blob/$(git rev-parse --abbrev-ref HEAD)/$file$line
}
git-pull() {
local origin="origin"
local branch=$(:git:branch)
if [ $# -ne 0 ]; then
local option=$1
if [ "$option" = "upstream" ]; then
origin=$option
else
branch=$option
fi
fi
stashed=$(git stash)
git pull --stat --rebase $origin $branch
if [[ ! "$stashed" =~ "No local changes to save" ]]; then
git stash pop
fi
}
aur-get-sources() {
local package=$1
cd /tmp/
yay -G -a "$package"
cd "$package"
cat PKGBUILD
}
git-rebase-interactive() {
if [[ "$1" =~ ^[0-9]+$ ]]; then
git rebase -i "HEAD~$1"
return $?
fi
git rebase -i $@
}
git-reset-soft() {
if [[ "$1" =~ ^[0-9]+$ ]]; then
git reset --soft "HEAD~$1"
return $?
fi
git reset --soft $@
}
git-clean-powered() {
git clean -ffdx
}
makepkg-clean() {
local branch="$1"
rm -rf *.xz
rm -rf src pkg
BRANCH="$branch" makepkg -f
restore-pkgver-pkgrel
}
sed-files() {
local from="$1"
local to="$2"
shift 2
sed-replace "$from" "$to" $(sift "$from" -l) "$@"
}
sed-delete() {
local query="$1"
shift 1
delete_pattern="${query//\//\\/}"
sed -r -i "/${delete_pattern}/d" $(sift "$query" -l) "$@"
}
git-clone-sources() {
cd ~/sources/
git clone "$1"
}
:cd-sources() {
cd ~/sources/"$@"
}
:is-interactive() {
(
exec 9>&1
if [[ "$(readlink /dev/fd/9)" == *"pipe:"* ]]; then
return 1
else
return 0
fi
)
return $?
}
:nmap:online() {
nmap -sP -PS22 $@ -oG - \
| awk '/Status: Up/{ print $2; }' \
| tee /dev/stderr \
}
:sources:get() {
local dir=$(sources-get "${@}")
cd "${dir}"
}
:aur:spawn() {
yes | EDITOR=cat yay "$@"
}
:aur:search() {
local search=$(:aur:spawn -Ss "$@")
grep -P "$@|" <<< "$search"
}
:aur:install-or-search() {
if [[ "$#" -eq 2 && "$2" == ":" ]]; then
:aur:search "$1"
else
:aur:spawn -S "$@"
fi
}
:git:get-master() {
if git rev-parse --verify master 2>/dev/null; then
echo "master"
else
echo "main"
fi
}
:git:master() {
master=$(:git:get-master)
git fetch && \
git checkout origin/$master && \
git branch -D $master && \
git checkout -b $master
if [[ "$1" ]]; then
git checkout -b "$1"
fi
}
:git:merge() {
local branch=$(:git:branch)
git checkout master
git merge origin/"$branch"
}
:git:branch() {
git rev-parse --abbrev-ref HEAD
}
:rtorrent:select() {
torrent=$(
find ~/Downloads/ -maxdepth 1 -type f -name '*.torrent' \
| while read filename; do
name=$(transmission-show "$filename" \
| grep -P '^Name: ' \
| sed -r 's/Name:\s+//')
echo "$(basename "$filename") :: $name"
done \
| fzf
)
if [[ "$torrent" ]]; then
torrent=$(sed 's/ :: .*$//' <<< "$torrent")
qbittorrent ~/Downloads/"$torrent"
fi
}
:mplayer:run() {
#if [[ $# -eq 0 ]]; then
#mplayer $(/bin/ls | grep -vP '\.(jpg|jpeg|png|log|txt|cue)$')
#else
mplayer "$@"
#fi
}
zle -N :rtorrent:select
:move() {
local from=""
if [[ -f /var/run/user/$(id -u)/buffer-move ]]; then
from="$(cat /var/run/user/$(id -u)/buffer-move)"
fi
if [[ ! "$from" ]]; then
if [[ ! "$1" ]]; then
echo "target is not specified" >&2
return 1
fi
echo "$(readlink -f "$1")" > /var/run/user/$(id -u)/buffer-move
return 0
fi
to="$1"
if [[ ! "$to" ]]; then
to=$(basename "$from")
fi
echo "$from -> $to" >&2
mv "$from" "$to"
rm /var/run/user/$(id -u)/buffer-move
}
:rsync() {
rsync -av --stats --progress "$@"
}
:axel() {
local link=$1
local threads=${2:-10}
axel -a -n $threads "$link"
}
:process:info() {
local name="$1"
local processes=$(pgrep -d, -x "$name")
if [[ ! "$processes" ]]; then
return 1;
fi
ps uf -p "$processes"
}
:watcher() {
source ~/deadfiles/bin/watchit
:watchit "${@}"
}
:process:kill() {
local name="$1"
if [[ ! "$name" ]]; then
echo "no name specified"
return 1
fi
pkill -9 "$name" || pkill -f -9 "$name"
}
:gitignore:add() {
while [[ "$1" ]]; do
local filename="$1"
echo "$1" >> .gitignore
shift
done
}
:pacman:filter-executable() {
while read package file; do
if [[ -f "$file" && -x "$file" ]]; then
echo "$package $file"
fi
done
}
:mplayer:dir-audio() {
# subshell for trap
(
local playlist="$(mktemp)"
trap "rm $playlist" EXIT
while [[ "$1" ]]; do
find "${1:-.}" \
-type f \
-iregex ".*\.\(m4a\|aac\|flac\|mp3\|ogg\|wav\)$" \
-print0 \
| xargs -0 -n1 readlink -f \
| sort >> "$playlist"
shift
done
mplayer -novideo -playlist "$playlist"
)
}
:copy-line() {
head -n "$1" | tail -n 1 | copy-to-clipboard
}
:join_by() {
local d=$1;
shift;
echo -n "$1";
shift;
printf "%s" "${@/#/$d}";
}
:search:go() {
EXT=go :search "${@}"
}
:search() {
ag "${@}"
}
:circleci:exec() {
circleci-cli --token-file ~/.config/circleci/token "${@}"
}
:circleci:recent-build() {
watch -c -n0.0 circleci-recent-build
}
:find-gem() {
if gem=$(gem list \
| grep "${1} " \
| sed 's/ (/-/' \
| sed 's/)//'); then
echo "gem: ${gem}"
cd /usr/lib/ruby/gems/2.5.0/gems/"$gem"
fi
}
}
{
alias -g I='<<<'
alias -g '#pe'='| :pacman:filter-executable'
alias -g '#t'='| :copy-line'
alias -g '#k'='| karma-grep'
}
ssha() {
rs
if [[ ! "${_ssh_added}" ]]; then
if [[ ! "$_SSH_AUTH_SOCK" ]]; then
eval "$(ssh-agent -s)"
fi
ssh-add ~/.ssh/id_rsa
_ssh_added=true
fi
/bin/ssh -A "$@"
}
:hosts:add() {
local server="$1"
local hostname="$2"
if ! grep -qP '^[0-9\.]+$' <<< "$server"; then
echo "$server is not an ip address" >&2
return 1
fi
echo "$server $hostname" | sudo tee -a /etc/hosts
}