|
@@ -13,6 +13,21 @@ test -f /usr/share/git-core/contrib/completion/git-prompt.sh \
|
13
|
13
|
### SUBZ ###
|
14
|
14
|
### '''' ###
|
15
|
15
|
|
|
16
|
+prepend() {
|
|
17
|
+ #
|
|
18
|
+ # pre-pend $2 to filename $1
|
|
19
|
+ #
|
|
20
|
+ local path=$1
|
|
21
|
+ local prefix=$2
|
|
22
|
+ local dirpath
|
|
23
|
+ local filename
|
|
24
|
+ local abspath
|
|
25
|
+ abspath=$(readlink -f "$path")
|
|
26
|
+ dirpath=$(dirname "$abspath")
|
|
27
|
+ filename=$(basename "$abspath")
|
|
28
|
+ echo mv "$path" "$dirpath/$prefix-$filename"
|
|
29
|
+}
|
|
30
|
+
|
16
|
31
|
smv() {
|
17
|
32
|
#
|
18
|
33
|
# scp but rm the source
|
|
@@ -39,17 +54,58 @@ smvr() {
|
39
|
54
|
scp -r "$src" "$dst" && rm -r "$src"
|
40
|
55
|
}
|
41
|
56
|
|
42
|
|
-
|
43
|
|
-bb() {
|
|
57
|
+snore() {
|
44
|
58
|
#
|
45
|
|
- # Ring the bell
|
|
59
|
+ # Sleep loudly-ish for $1 time
|
46
|
60
|
#
|
47
|
61
|
local stime=${1:-0}
|
48
|
62
|
test "$stime" == 0 || echo -e "sleeping for $BASHUM_COLOR_LGREEN$stime$BASHUM_COLOR_NORMAL"
|
49
|
63
|
sleep "$stime"
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+dotsleep() {
|
|
67
|
+ #
|
|
68
|
+ # Sleep with dots for $1 seconds
|
|
69
|
+ #
|
|
70
|
+ local secs=$1
|
|
71
|
+ echo -e "sleeping for $BASHUM_COLOR_LGREEN$secs$BASHUM_COLOR_NORMAL seconds"
|
|
72
|
+ local secs_togo=$secs
|
|
73
|
+ while test "$secs_togo" -gt 0; do
|
|
74
|
+ sleep 1
|
|
75
|
+ echo -n .
|
|
76
|
+ ((secs_togo--))
|
|
77
|
+ done
|
|
78
|
+ echo
|
|
79
|
+}
|
|
80
|
+
|
|
81
|
+bb() {
|
|
82
|
+ #
|
|
83
|
+ # Ring the bell after $1 time of sleep
|
|
84
|
+ #
|
|
85
|
+ local stime=${1:-0}
|
|
86
|
+ snore "$stime"
|
50
|
87
|
printf '\a'
|
51
|
88
|
}
|
52
|
89
|
|
|
90
|
+spec_cksources() {
|
|
91
|
+ #
|
|
92
|
+ # Check Source?: URL's in RPM spec file $1
|
|
93
|
+ #
|
|
94
|
+ local file=$1
|
|
95
|
+ local hdr
|
|
96
|
+ local url
|
|
97
|
+ rpmspec -P "$file" \
|
|
98
|
+ | grep -E 'Source[0-9]+: *http' \
|
|
99
|
+ | while read -r hdr url; do
|
|
100
|
+ echo -n "$hdr: $url .."
|
|
101
|
+ curl -fsSL -I "$url" >/dev/null || {
|
|
102
|
+ echo fail
|
|
103
|
+ return 1
|
|
104
|
+ }
|
|
105
|
+ echo ok
|
|
106
|
+ done
|
|
107
|
+}
|
|
108
|
+
|
53
|
109
|
nn() {
|
54
|
110
|
#
|
55
|
111
|
# Ring the bell and send notification $1 after $2 time
|
|
@@ -72,10 +128,34 @@ pp() {
|
72
|
128
|
read -r junk -p "Press Enter to continue"
|
73
|
129
|
}
|
74
|
130
|
|
|
131
|
+wrep() {
|
|
132
|
+ #
|
|
133
|
+ # Print each line on STDIN $1 times horizontally
|
|
134
|
+ #
|
|
135
|
+ echo >&2 "use sdup -w instead!"
|
|
136
|
+ local rep=${1:-1}; shift
|
|
137
|
+ local delim=${1:-" "}; shift
|
|
138
|
+ local line
|
|
139
|
+ local n
|
|
140
|
+ while read -r line; do
|
|
141
|
+ local head=true
|
|
142
|
+ n=$rep
|
|
143
|
+ while test "$n" -gt 0;
|
|
144
|
+ do
|
|
145
|
+ $head || echo -n "$delim"
|
|
146
|
+ $head && head=false
|
|
147
|
+ echo -n "$line"
|
|
148
|
+ ((n--))
|
|
149
|
+ done
|
|
150
|
+ echo
|
|
151
|
+ done
|
|
152
|
+}
|
|
153
|
+
|
75
|
154
|
lrep() {
|
76
|
155
|
#
|
77
|
156
|
# Print each line on STDIN $1 times
|
78
|
157
|
#
|
|
158
|
+ echo >&2 "use sdup -l instead!"
|
79
|
159
|
local rep=${1:-1}; shift
|
80
|
160
|
local line
|
81
|
161
|
local n
|
|
@@ -93,6 +173,7 @@ prep() {
|
93
|
173
|
#
|
94
|
174
|
# Print STDIN $1 times
|
95
|
175
|
#
|
|
176
|
+ echo >&2 "use sdup instead!"
|
96
|
177
|
local rep=${1:-1}; shift
|
97
|
178
|
local data
|
98
|
179
|
data=$(cat)
|
|
@@ -419,13 +500,73 @@ xop() {
|
419
|
500
|
# Common clipboard operations with fixnl() on top
|
420
|
501
|
#
|
421
|
502
|
local op=$1
|
422
|
|
- local file=${2:-/dev/stdin}
|
|
503
|
+ local arg=${2:-/dev/stdin}
|
423
|
504
|
case $op in
|
424
|
|
- oo) xclip -selection clipboard -o | fixnl ;;
|
425
|
|
- o) xclip -o | fixnl ;;
|
426
|
|
- ii) fixnl -c | xclip -selection clipboard -i ;;
|
427
|
|
- i) fixnl -c | xclip -i ;;
|
428
|
|
- esac <"$file"
|
|
505
|
+ aa) <<<"$arg" fixnl -c | xclip -selection clipboard -i ;;
|
|
506
|
+ a) <<<"$arg" fixnl -c | xclip -i ;;
|
|
507
|
+ ii) <"$arg" fixnl -c | xclip -selection clipboard -i ;;
|
|
508
|
+ i) <"$arg" fixnl -c | xclip -i ;;
|
|
509
|
+ oo) <"$arg" xclip -selection clipboard -o | fixnl ;;
|
|
510
|
+ o) <"$arg" xclip -o | fixnl ;;
|
|
511
|
+ *) return 2 ;;
|
|
512
|
+ esac
|
|
513
|
+}
|
|
514
|
+
|
|
515
|
+xt() {
|
|
516
|
+ #
|
|
517
|
+ # Type out selection clipboard content using xdotool
|
|
518
|
+ #
|
|
519
|
+ local stime=${1:-3}
|
|
520
|
+ local body
|
|
521
|
+ snore "$stime"
|
|
522
|
+ body=$(xo)
|
|
523
|
+ xdotool type "$body"
|
|
524
|
+}
|
|
525
|
+
|
|
526
|
+xtt() {
|
|
527
|
+ #
|
|
528
|
+ # Type out C-C clipboard content using xdotool
|
|
529
|
+ #
|
|
530
|
+ local stime=${1:-3}
|
|
531
|
+ local body
|
|
532
|
+ snore "$stime"
|
|
533
|
+ body=$(xoo)
|
|
534
|
+ xdotool type "$body"
|
|
535
|
+}
|
|
536
|
+
|
|
537
|
+xdl() {
|
|
538
|
+ #
|
|
539
|
+ # Download URL from primary clipboard to path $1
|
|
540
|
+ #
|
|
541
|
+ local dest=$1
|
|
542
|
+ local url
|
|
543
|
+ url=$(xo)
|
|
544
|
+ _xdl "$dest" "$url"
|
|
545
|
+}
|
|
546
|
+
|
|
547
|
+xxdl() {
|
|
548
|
+ #
|
|
549
|
+ # Download URL from C-C clipboard to path $1
|
|
550
|
+ #
|
|
551
|
+ local dest=$1
|
|
552
|
+ local url
|
|
553
|
+ url=$(xoo)
|
|
554
|
+ _xdl "$dest" "$url"
|
|
555
|
+}
|
|
556
|
+
|
|
557
|
+_xdl() {
|
|
558
|
+ #
|
|
559
|
+ # Download URL from primary clipboard to path $1
|
|
560
|
+ #
|
|
561
|
+ local dest=$1
|
|
562
|
+ local url=$2
|
|
563
|
+ local es
|
|
564
|
+ test -n "$dest" || return 2
|
|
565
|
+ test -f "$dest" && return 2
|
|
566
|
+ test -n "$url" || return 2
|
|
567
|
+ curl -fsSL "$url" >"$dest"; es=$?
|
|
568
|
+ bb
|
|
569
|
+ return $es
|
429
|
570
|
}
|
430
|
571
|
|
431
|
572
|
xod() {
|
|
@@ -481,7 +622,7 @@ xvxx() {
|
481
|
622
|
# back to the browser and paste it over the old (still selected) text.
|
482
|
623
|
# That's it, no need to make up and save temporary files.
|
483
|
624
|
#
|
484
|
|
- # If you quickly realize you need to re-edit the text, use xvvx().
|
|
625
|
+ # If you quickly realize you need to re-edit the text, use xxvxx().
|
485
|
626
|
#
|
486
|
627
|
xop o | vipe | xop ii
|
487
|
628
|
}
|
|
@@ -509,7 +650,37 @@ xpst() {
|
509
|
650
|
echo "does not exist: $path"
|
510
|
651
|
continue
|
511
|
652
|
}
|
512
|
|
- cp -r "$path" .
|
|
653
|
+ cp -ar "$path" .
|
|
654
|
+ done
|
|
655
|
+}
|
|
656
|
+
|
|
657
|
+xpst_l() {
|
|
658
|
+ #
|
|
659
|
+ # Symlink paths from clipboard, with relative paths
|
|
660
|
+ #
|
|
661
|
+ { xop o; echo; } \
|
|
662
|
+ | while read -r path; do
|
|
663
|
+ echo "path='$path'" >&2
|
|
664
|
+ test -e "$path" || {
|
|
665
|
+ echo "does not exist: $path"
|
|
666
|
+ continue
|
|
667
|
+ }
|
|
668
|
+ ln -sr "$path" .
|
|
669
|
+ done
|
|
670
|
+}
|
|
671
|
+
|
|
672
|
+xpst_la() {
|
|
673
|
+ #
|
|
674
|
+ # Symlink paths from clipboard, with absolute paths
|
|
675
|
+ #
|
|
676
|
+ { xop o; echo; } \
|
|
677
|
+ | while read -r path; do
|
|
678
|
+ echo "path='$path'" >&2
|
|
679
|
+ test -e "$path" || {
|
|
680
|
+ echo "does not exist: $path"
|
|
681
|
+ continue
|
|
682
|
+ }
|
|
683
|
+ ln -s "$path" .
|
513
|
684
|
done
|
514
|
685
|
}
|
515
|
686
|
|
|
@@ -535,7 +706,7 @@ vxx() {
|
535
|
706
|
# or another GUI application. Run the command with `vxx`, edit
|
536
|
707
|
# the text, move back to the application and paste it.
|
537
|
708
|
#
|
538
|
|
- # If you quickly realize you need to re-edit the text, use xvvx().
|
|
709
|
+ # If you quickly realize you need to re-edit the text, use xxvxx().
|
539
|
710
|
#
|
540
|
711
|
vipe | xop ii
|
541
|
712
|
}
|
|
@@ -544,7 +715,7 @@ xcxx() {
|
544
|
715
|
#
|
545
|
716
|
# Filter text in primary clipboard using command $@ and save it to C-C clipboard
|
546
|
717
|
#
|
547
|
|
- # Similar to xvvx() but instead of interactive editing, provided filter
|
|
718
|
+ # Similar to xvxx() but instead of interactive editing, provided filter
|
548
|
719
|
# command is run.
|
549
|
720
|
#
|
550
|
721
|
local cmd=("$@")
|
|
@@ -552,6 +723,42 @@ xcxx() {
|
552
|
723
|
return "${PIPESTATUS[1]}"
|
553
|
724
|
}
|
554
|
725
|
|
|
726
|
+xtrans() {
|
|
727
|
+ #
|
|
728
|
+ # Translate text in primary clipboard using code $1 and output it
|
|
729
|
+ #
|
|
730
|
+ # Similar to xcxx but assumes code snippet, and prints the result
|
|
731
|
+ # to make it easier to check it visually.
|
|
732
|
+ #
|
|
733
|
+ local code=$1
|
|
734
|
+ test $# -gt 1 && code=$(printf '%q ' "$@")
|
|
735
|
+# echo >&2 "debug:code=$code"
|
|
736
|
+ local es
|
|
737
|
+ xop o | bash -c "$code" | xop ii
|
|
738
|
+ es="${PIPESTATUS[1]}"
|
|
739
|
+ xop oo >&2
|
|
740
|
+ echo >&2
|
|
741
|
+ return "$es"
|
|
742
|
+}
|
|
743
|
+
|
|
744
|
+xfromc() {
|
|
745
|
+ #
|
|
746
|
+ # Get text using code $1 and output it
|
|
747
|
+ #
|
|
748
|
+ # Similar to xtrans but assumes code snippet, and prints the result
|
|
749
|
+ # to make it easier to check it visually.
|
|
750
|
+ #
|
|
751
|
+ local code=$1
|
|
752
|
+ test $# -gt 1 && code=$(printf '%q ' "$@")
|
|
753
|
+ echo >&2 "debug:code=$code"
|
|
754
|
+ local es
|
|
755
|
+ bash -c "$code" | xop ii
|
|
756
|
+ es="${PIPESTATUS[0]}"
|
|
757
|
+ xop oo >&2
|
|
758
|
+ echo >&2
|
|
759
|
+ return "$es"
|
|
760
|
+}
|
|
761
|
+
|
555
|
762
|
vx() {
|
556
|
763
|
#
|
557
|
764
|
# Edit stdin and save it to primary clipboard
|
|
@@ -609,6 +816,14 @@ cal() {
|
609
|
816
|
64:*)
|
610
|
817
|
command cal -M "$@"
|
611
|
818
|
;;
|
|
819
|
+ 127:*)
|
|
820
|
+ echo >&2 "cal(): cal command is not installed"
|
|
821
|
+ return 127
|
|
822
|
+ ;;
|
|
823
|
+ *)
|
|
824
|
+ echo >&2 "cal(): error: cal_es=$cal_es, cal_v=$cal_v"
|
|
825
|
+ return 5
|
|
826
|
+ ;;
|
612
|
827
|
esac
|
613
|
828
|
}
|
614
|
829
|
|
|
@@ -617,18 +832,17 @@ cal() {
|
617
|
832
|
### '''' ###
|
618
|
833
|
|
619
|
834
|
HISTCONTROL=ignoredups:erasedups
|
620
|
|
-shopt -s histappend
|
621
|
|
-PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"
|
|
835
|
+# shopt -s histappend
|
|
836
|
+# PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"
|
622
|
837
|
|
623
|
838
|
HISTIGNORE="$HISTIGNORE:ls:ll:la:cd"
|
624
|
|
-HISTIGNORE="$HISTIGNORE:git dc:git st"
|
625
|
|
-HISTIGNORE="$HISTIGNORE:reset"
|
|
839
|
+HISTIGNORE="$HISTIGNORE:git st"
|
626
|
840
|
HISTIGNORE="$HISTIGNORE:se *:sc *"
|
627
|
|
-HISTSIZE=-1
|
628
|
|
-HISTFILESIZE=100000
|
|
841
|
+HISTSIZE=33333
|
|
842
|
+HISTFILESIZE=33333
|
629
|
843
|
HISTTIMEFORMAT='%F %T '
|
630
|
844
|
GLOBIGNORE=.:..
|
631
|
|
-shopt -s histverify
|
|
845
|
+# shopt -s histverify
|
632
|
846
|
|
633
|
847
|
# some more aliases
|
634
|
848
|
alias cls='clear'
|
|
@@ -650,25 +864,35 @@ alias lsblk='lsblk -o +UUID,LABEL'
|
650
|
864
|
alias pstree='pstree -h'
|
651
|
865
|
alias virsh='virsh --connect qemu:///system'
|
652
|
866
|
alias wttr='curl -s "wttr.in/?1&n&q"'
|
653
|
|
-alias xaa='xclip -o | audit2allow'
|
654
|
867
|
alias xi='xop i'
|
655
|
868
|
alias xii='xop ii'
|
|
869
|
+alias xa='xop a'
|
|
870
|
+alias xaa='xop aa'
|
656
|
871
|
alias xo='xop o'
|
657
|
872
|
alias xoo='xop oo'
|
658
|
873
|
alias reboot="echo -n . ; sync ; echo -n . ; sync ; echo -n . ; systemctl reboot"
|
659
|
874
|
alias poweroff="echo -n . ; sync ; echo -n . ; sync ; echo -n . ; systemctl poweroff"
|
660
|
875
|
|
661
|
|
-x4x() {
|
|
876
|
+x4xx() {
|
662
|
877
|
#
|
663
|
878
|
# Pad text from primary clipboard with 4 spaces; save to C-C clipboard
|
664
|
879
|
#
|
665
|
880
|
# ...that is, for inclusion as Markdown verbatim text.
|
666
|
881
|
#
|
667
|
|
- xo | pad4 | xii
|
|
882
|
+ xop oo | pad4 | xop ii
|
668
|
883
|
}
|
669
|
884
|
|
670
|
|
-RV_TMP="/tmp/bash-rv"
|
671
|
|
-mkdir -p "$RV_TMP"
|
|
885
|
+x4x() {
|
|
886
|
+ #
|
|
887
|
+ # Pad text from primary clipboard with 4 spaces; save back
|
|
888
|
+ #
|
|
889
|
+ # ...that is, for inclusion as Markdown verbatim text.
|
|
890
|
+ #
|
|
891
|
+ xop -o | pad4 | xop i
|
|
892
|
+}
|
|
893
|
+
|
|
894
|
+BASHUM__RV_TMP="/tmp/bashum-rv"
|
|
895
|
+mkdir -p "$BASHUM__RV_TMP"
|
672
|
896
|
|
673
|
897
|
### ...... ###
|
674
|
898
|
### OTHERS ###
|
|
@@ -686,6 +910,8 @@ export PRETTY_DEBUG_EXCLUDE=inigrep
|
686
|
910
|
export MDVIMB__CONVERTER=cmark
|
687
|
911
|
export MDVIMB__STYLE=darkzen # pergamen
|
688
|
912
|
|
|
913
|
+export MYPY_CACHE_DIR="$HOME/.cache/mypy/the_darn_cache"
|
|
914
|
+
|
689
|
915
|
#shellcheck disable=SC2034
|
690
|
916
|
{
|
691
|
917
|
GIT_PS1_SHOWDIRTYSTATE=true
|