2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4 # this gets sourced. shebang is just for file mode detection
6 # note, to catch errors in functions but not outside, do:
9 # trap 'trap ERR' RETURN
18 # remove all aliases. aliases provided by the system tend to get in the way,
19 # for example, error happens if I try to define a function the same name as an alias
22 # remove gnome keyring warning messages
23 # there is probably a more proper way, but I didnt find any easily on google
24 # now using xfce+xmonad instead of vanilla xmonad, so disabling this
25 #unset GNOME_KEYRING_CONTROL
27 # use extra globing features.
29 # include .files when globbing, but ignore files name . and ..
30 # setting this also sets dotglob.
31 export GLOBIGNORE
="*/.:*/.."
33 # broken with bash_completion package. Saw a bug for this once. dont anymore.
34 # still broken in wheezy
35 # still buggered in latest stable from the web, version 2.1
36 # perhaps its fixed in newer git version, which fails to make for me
37 # this note is from 6-2014.
38 # still broken in flidas.
41 # make tab on an empty line do nothing
42 shopt -s no_empty_cmd_completion
44 # fix spelling errors for cd, only in interactive shell
46 # append history instead of overwritting it
48 # for compatibility, per gentoo/debian bashrc
50 # attempt to save multiline single commands as single history entries.
57 if [[ $RLC_INSIDE_EMACS ]]; then
58 # EMACS is used by bash on startup, but we dont need it anymore.
59 # plus I hit a bug in a makefile which inherited it
61 export RLC_INSIDE_EMACS
64 # scp completion does not work, but this doesnt fix it. todo, figure this out
65 complete
-r scp
&> /dev
/null
66 # todo, remote file completion fails, figure out how to turn it off
67 export NODE_DISABLE_COLORS
=1
68 # This gets rid of ugly terminal escape chars in node repl
69 # sometime, Id like to have completion working in emacs shell for node
70 # the offending chars can be found in lib/readline.js,
71 # things that do like:
72 # stream.write('\x1b[' + (x + 1) + 'G');
73 # We can remove them and keep readline, for example by doing this
76 # var readline = require('readline');
77 # readline.cursorTo = function(a,b,c) {};
78 # readline.clearScreenDown = function(a) {};
79 # const repl = require('repl');
80 # var replServer = repl.start('');
82 # no prompt, or else readline complete seems to be confused, based
83 # on our column being different? node probably needs to send
84 # different kind of escape sequence that is not ugly. Anyways,
85 # completion doesnt work yet even with the ugly prompt, so whatever
87 export NODE_NO_READLINE
=1
91 # emacs has a different default search path than the info command. This
92 # adds the info defaults to emacs, but not the reverse, because I dun
93 # care much about the cli. The search path is only on the cli if you run
94 # "info xxx", or in emacs if you run '(info xxx)', so not that
95 # important, but might as well fix it.
97 # info info says this path is what was compiled, and its not documented
98 # anywhere. Through source grepping, i found it in filesys.h of the info
99 # source in trisquel flidas.
101 # Traling : means for emacs to add its own stuff on to the end.
103 export INFOPATH
=$PATH:/usr
/local
/info
:/usr
/info
:/usr
/local
/lib
/info
:/usr
/lib
/info
:/usr
/local
/gnu
/info
:/usr
/local
/gnu
/lib
/info
:/usr
/gnu
/info
:/usr
/gnu
/lib
/info
:/opt
/gnu
/info
:/usr
/share
/info
:/usr
/share
/lib
/info
:/usr
/local
/share
/info
:/usr
/local
/share
/lib
/info
:/usr
/gnu
/lib
/emacs
/info
:/usr
/local
/gnu
/lib
/emacs
/info
:/usr
/local
/lib
/emacs
/info
:/usr
/local
/emacs
/info
:.
:
105 if [[ $
- == *i
* ]]; then
106 # for readline-complete.el
107 if [[ $RLC_INSIDE_EMACS ]]; then
108 # all for readline-complete.el
110 bind 'set horizontal-scroll-mode on'
111 bind 'set print-completions-horizontally on'
112 bind '"\C-i": self-insert'
115 if [[ $KONSOLE_PROFILE_NAME ]]; then
119 # todo: not sure this works in sakura
121 #bind "\C-w": kill-region
122 # sakura == xterm-256color
124 if [[ $TERM == xterm
* ]]; then
125 # control + arrow keys. for other terminals, see http://unix.stackexchange.com/questions/10806/how-to-change-previous-next-word-shortcut-in-bash
126 bind '"\e[1;5C": shell-forward-word' 2>/dev
/null
127 bind '"\e[1;5D": shell-backward-word' 2>/dev
/null
129 # make ctrl-backspace work. for konsole, i fixed it through
130 # /home/iank/.local/share/konsole/default.keytab
132 bind '"\eOc": shell-forward-word'
133 bind '"\eOd": shell-backward-word'
135 # i cant remember why i did this, probably to free up some keys to bind
136 # to other things in bash.
137 # other than C-c and C-z, the rest defined by stty -a are, at least in
138 # gnome-terminal, overridden by bash, or disabled by the system
139 stty lnext undef stop undef start undef
145 # history number. History expansion is good.
147 # history file size limit, set to unlimited.
148 # this needs to be different from the default because
149 # default HISTFILESIZE is 500 and could clobber our history
151 # max commands 1 session can append/read from history
153 # the time format display when doing the history command
154 # also, setting this makes the history file record time
155 # of each command as seconds from the epoch
156 HISTTIMEFORMAT
="%Y-%m-%d %I:%M %p "
157 # consecutive duplicate lines dont go in history
158 HISTCONTROL
=ignoredups
159 # works in addition to HISTCONTROL to do more flexible things
160 # it could also do the same things as HISTCONTROL and thus replace it,
161 # but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
162 HISTIGNORE
='pass *:[ ]*:otp *:oathtool *'
164 export BC_LINE_LENGTH
=0
166 export PROFILE_TASKS_TASK_OUTPUT_LIMIT
=100
168 # note, if I use a machine I dont want files readable by all users, set
169 # umask 077 # If fewer than 4 digits are entered, leading zeros are assumed
171 # i for insensitive. the rest from
172 # X means dont remove the current screenworth of output upon exit
173 # R means to show colors n things
175 export SYSTEMD_LESS
=$LESS
182 # if someone exported $SOE (stop on error), catch errors.
184 # Note, on debian this results in the following warning when in ssh,
185 # hich I haven't figured out how to fix. It doesn't happen if we source
186 # after the shell has started
188 # bash: /usr/share/bashdb/bashdb-main.inc: No such file or directory
189 # bash: warning: cannot start debugger; debugging mode disabled
191 if [[ -e /a
/bin
/errhandle
/err
]]; then
192 source /a
/bin
/errhandle
/err
196 # based on readme.debian. dunno if this will break on other distros.
197 if [[ -s /usr
/share
/wcd
/wcd-include.sh
]]; then
198 source /usr
/share
/wcd
/wcd-include.sh
201 if [[ -s /a
/bin
/small-misc-bash
/ll-function
]]; then
202 # shellcheck source=/a/bin/small-misc-bash/ll-function
203 source /a
/bin
/small-misc-bash
/ll-function
204 elif [[ -s ~
/.iank
/ll-function
]]; then
205 source ~
/.iank
/ll-function
213 ....
() { c ..
/..
/..
; }
214 .....
() { c ..
/..
/..
/..
; }
215 ......
() { c ..
/..
/..
/..
/..
; }
217 # file cut copy and paste, like the text buffers :)
218 # I havnt tested these.
219 _fbufferinit
() { # internal use
220 ! [[ $my_f_tempdir ]] && my_f_tempdir
=$
(mktemp
-d)
221 rm -rf "${my_f_tempdir:?}"/*
225 cp "$@" "$my_f_tempdir"/
229 mv "$@" "$my_f_tempdir"/
231 fpst
() { # file paste
232 [[ $2 ]] && { echo too many arguments
; return 1; }
234 cp "$my_f_tempdir"/* "$target"
240 read -r ip port
< <(timeout
1 ssh -oBatchMode=yes -oControlMaster=no
-oControlPath=/ -v $1 |
& sed -rn "s/debug1: Connecting to $host \[([^\]*)] port ([0-9]+).*/\1 \2/p")
242 echo "khfix: ssh failed"
245 if [[ $port != 22 ]]; then
246 ip_entry
="[$ip]:$port"
247 host_entry
="[$host]:$port"
252 ssh-keygen
-R "$host_entry" -f $
(readlink
-f ~
/.ssh
/known_hosts
)
253 echo "khfix: removing key for $ip_entry"
254 ssh-keygen
-R "$ip_entry" -f $
(readlink
-f ~
/.ssh
/known_hosts
)
256 khfix
() { # known hosts fix
257 _khfix_common
"$@" ||
return 1
267 x
=$
(readlink
-nf "${1:-$PWD}")
268 # yes, its kinda dumb that xclip/xsel cant do this in one invocation
269 echo -n "$x" | xclip
-selection clipboard
273 ack
() { ack-grep
"$@"; }
282 if type -p wcd
&>/dev
/null
; then
283 if [[ $RLC_INSIDE_EMACS ]]; then
284 c
() { wcd
-c -z 50 -o "$@"; }
286 # lets see what the fancy terminal does from time to time
287 c
() { wcd
-c -z 50 "$@"; }
293 c4
() { c
/var
/log
/exim4
; }
295 caa
() { git commit
--amend --no-edit -a; }
298 # shellcheck disable=SC2033
299 find -L $1 -type f
-not \
( -name .svn
-prune -o -name .git
-prune \
300 -o -name .hg
-prune -o -name .editor-backups
-prune \
301 -o -name .undo-tree-history
-prune \
) \
302 -exec bash
-lc 'hr; echo "$1"; hr; cat "$1"' _
{} \
; 2>/dev
/null
306 calc
() { echo "scale=3; $*" |
bc -l; }
307 # no having to type quotes, but also no command history:
311 echo "scale=3; $x" |
bc -l
319 ccat
() { # config cat. see a config without extra lines.
320 grep '^\s*[^;[:space:]#]' "$@"
325 # join options which are continued to multiples lines onto one line
327 while IFS
= read -r line
; do
328 # remove leading spaces/tabs. assumes extglob
329 if [[ $line == "[ ]*" ]]; then
335 elif [[ $line == *=* ]]; then
336 echo "$pastline" >> "$2"
339 pastline
="$pastline $line"
341 done < <(grep -vE '^([ \t]*#|^[ \t]*$)' "$1")
342 echo "$pastline" >> "$2"
347 # setup for format of postfix, eg:
350 local pastline unified f1 f2
354 _cdiff-prep
"$1" "$f1"
355 _cdiff-prep
"$2" "$f2"
356 cat "$f1" "$f2" |
grep -Po '^[^=]+=' |
sort |
uniq > "$unified"
357 while IFS
= read -r line
; do
358 # the default bright red / blue doesnt work in emacs shell
359 dwdiff
-cblue,red
-A best
-d " ," <(grep "^$line" "$f1" ||
echo ) <(grep "^$line" "$f2" ||
echo ) | colordiff
367 inotifywait
-m "$dir" -e create
-e moved_to |
368 # shellcheck disable=SC2030
369 while read -r filedir _
file; do
372 calc $
((SECONDS
- start
)) / 60
378 # shellcheck disable=SC2032
380 # makes it so chown -R symlink affects the symlink and its target.
381 if [[ $1 == -R ]]; then
383 command chown
-h "$@"
384 command chown
-R "$@"
395 # choose recent directory. cl = cd list
400 complete
-A stopped
-P '"%' -S '"' d
404 diff --strip-trailing-cr -w "$@" # diff content
411 safe_rename
"$x" "$y"
416 date "+%A, %B %d, %r" "$@"
419 dus
() { # du, sorted, default arg of
420 du
-sh ${@:-*} |
sort -h
427 # echo var. print var including escapes, etc
429 printf "%qEOL\n" "${!1}"
430 printf "%s" "${!1}" |
& hexdump -C
435 [[ ${#@} == 2 ]] ||
{ echo "error: ediff requires 2 arguments"; return 1; }
436 emacs
--eval "(ediff-files \"$1\" \"$2\")"
441 tail -F /var
/log
/exim
4/mainlog
-n 200
444 less /var
/log
/exim
4/mainlog
447 exiqgrep
-i |
while read i
; do
448 exim
-Mvh $i; hr
; exim
-Mvb $i; hr
;
449 exigrep
$i /var
/log
/exim
4/mainlog
; hr
454 # shellcheck disable=SC2032
461 # find array. make an array of file names found by find into $x
462 # argument: find arguments
463 # return: find results in an array $x
464 while read -rd ''; do
466 done < <(find "$@" -print0);
469 faf
() { # find all files. use -L to follow symlinks
470 find $@
-not \
( -name .svn
-prune -o -name .git
-prune \
471 -o -name .hg
-prune -o -name .editor-backups
-prune \
472 -o -name .undo-tree-history
-prune \
) -type f
2>/dev
/null
478 s mailq |gr frozen|
awk '{print $3}' |
while read -r id
; do
484 echo -e '\n\n##############################\n'
485 done |
tee -a /tmp
/frozen
489 while read -r line
; do
490 printf '%s\n' "$line"
491 ids
+=($
(printf '%s\n' "$line" |gr frozen|
awk '{print $3}'))
493 echo "sleeping for 2 in case you change your mind"
495 s exim
-Mrm "${ids[@]}"
499 # like -e for functions. returns on error.
500 # at the end of the function, disable with:
502 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
503 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"
509 local help="Usage: getdir [--help] PATH
510 Output the directory of PATH, or just PATH if it is a directory."
511 if [[ $1 == --help ]]; then
515 if [[ $# -ne 1 ]]; then
516 echo "getdir error: expected 1 argument, got $#"
523 dir
="$(dirname "$1")"
524 if [[ -d $dir ]]; then
527 echo "getdir error: directory does not exist"
533 git_empty_branch
() { # start an empty git branch. carefull, it deletes untracked files.
534 [[ $# == 1 ]] ||
{ echo 'need a branch name!'; return 1;}
536 root
=$
(gitroot
) ||
return 1 # function to set gitroot
538 git symbolic-ref HEAD refs
/heads
/$1
543 # shellcheck disable=SC2120
545 local help="Usage: gitroot [--help]
546 Print the full path to the root of the current git repo
548 Handles being within a .git directory, unlike git rev-parse --show-toplevel,
549 and works in older versions of git which did not have that."
550 if [[ $1 == --help ]]; then
555 p
=$
(git rev-parse
--git-dir) ||
{ echo "error: not in a git repo" ; return 1; }
556 [[ $p != /* ]] && p
=$PWD
561 # i got an error, gh not found when doing a pull request, it seems like it wants itself in it\'s path.
562 local _oldpath
="$PATH"
563 PATH
="$PATH:$HOME/node_modules/.bin"
569 # quit will prompt if the program crashes.
570 gdb
-ex=r
-ex=quit
--args emacs
"$@"; r
;
574 # kill the emacs daemon
579 grep -iIP --color=auto
"$@"
582 grr
() { # grep recursive
583 if [[ ${#@} == 1 ]]; then
584 grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto
"$@" .
586 grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto
"$@"
590 command rg
-i -M 200 "$@"
593 hr
() { # horizontal row. used to break up output
594 printf "$(tput setaf 5)â–ˆ$(tput sgr0)%.0s" $
(seq ${COLUMNS:-60})
598 hrcat
() { local f
; for f
; do [[ -f $f ]] ||
continue; hr
; echo "$f"; cat "$f"; done }
600 # get latest hub and run it
601 # main command to use:
602 # hub pull-request --no-edit
603 # --no-edit means to use the first commit\'s message as the pull request message.
604 # Also, you need to use a feature branch, not master in your fork.
605 # On first use, you input username/pass and it gets an oath token so you dont have to repeat
606 # it\'s at ~/.config/hub
608 local up uptar updir p
609 p
=/github
/hub
/releases
/
610 up
=https
://github.com
/$
(curl
-s https
://github.com
$p|
grep -o $p'download/[^/]*/hub-linux-amd64[^"]*' |
head -n1)
613 if [[ ! -e /a
/opt
/$updir ]]; then
614 rm -rf /a
/opt
/hub-linux-amd64
*
616 tar -C /a
/opt
-zxf /a
/opt
/$uptar
618 s
/a
/opt
/$updir/install
621 # save token across computers
622 if [[ ! -L ~
/.config
/hub
]]; then
623 if [[ -e ~
/.config
/hub
]]; then
624 mv ~
/.config
/hub
/p
/c
/subdir_files
/.config
/
626 if [[ -e /p
/c
/subdir_files
/.config
/hub
]]; then
634 # modified from ~/local/bin/git-completion.bash
635 # other completion commands are mostly taken from bash_completion package
636 complete
-o bashdefault
-o default
-o nospace
-F _git i
2>/dev
/null \
637 || complete
-o default
-o nospace
-F _git i
639 if ! type service
&>/dev
/null
; then
641 echo actually running
: systemctl
$2 $1
657 find -L .
-not \
( -name .svn
-prune -o -name .git
-prune \
658 -o -name .hg
-prune -o -name .editor-backups
-prune \
659 -o -name .undo-tree-history
-prune \
) -iname "*$**" 2>/dev
/null
663 s iptables
-A INPUT
-s $1 -j DROP
668 grep -Il "" "$@" &>/dev
/null
672 journalctl
-n 10000 -f "$@"
674 jr
() { journalctl
"$@" ; }
675 jrf
() { journalctl
-f "$@" ; }
678 if [[ $PWD == /[iap
] ]]; then
679 command ls -A --color=auto
-I lost
+found
"$@"
681 command ls -A --color=auto
"$@"
686 lcn
() { locate -i "*$**"; }
688 lg
() { LC_COLLATE
=C.UTF-8 ll
--group-directories-first; }
690 lt
() { ll
-tr "$@"; }
692 lld
() { ll
-d "$@"; }
694 low
() { # make filenames lowercase, remove bad chars
697 new
="${f,,}" # downcase
698 new
="${new//[^[:alnum:]._-]/_}" # sub bad chars
699 new
="${new#"${new%%[[:alnum:]]*}"}" # remove leading/trailing non-alnum
700 new
="${new%"${new##*[[:alnum:]]}"}"
701 # remove bad underscores, like __ and _._
702 new
=$
(echo $new |
sed -r 's/__+/_/g;s/_+([.-])|([.-])_+/\1/g')
703 safe_rename
"$f" "$new" ||
return 1
708 lower
() { # make first letter of filenames lowercase.
711 if [[ ${x::1} == [A-Z
] ]]; then
712 y
=$
(tr '[:upper:]' '[:lower:]' <<<"${x::1}")"${x:1}"
713 safe_rename
"$x" "$y" ||
return 1
719 k
() { # history search
720 grep -P --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
tail -n 80;
723 ks
() { # history search
724 grep -P --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
uniq;
729 # show make targets, via http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make
730 make -qp |
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
742 mkt
() { # mkdir and touch file
744 mkdir
-p "$(dirname "$path")"
748 # shellcheck disable=SC2032
749 mkdir
() { command mkdir
-p "$@"; }
752 # shellcheck disable=SC2024
753 sudo
tee -a /var
/log
/exim
4/paniclog-archive
</var
/log
/exim
4/paniclog
; sudo truncate
-s0 /var
/log
/exim
4/paniclog
756 p8
() { ping 8.8.8.8; }
757 p6
() { ping6
2001:4860:4860::8888; }
759 pkx
() { # package extract
760 local pkg cached tmp f
763 # shellcheck disable=SC2012
764 cached
=$
(ls -t /var
/cache
/apt
/archives
/$pkg* |
tail -n1 2>/dev
/null
)
765 if [[ $cached ]]; then
768 aptitude download
$pkg ||
return 1
770 tmp
=(*); f
=${tmp[0]} # only 1 expected
778 pid
=($
(pgrep
-f "$*"))
781 # shellcheck disable=SC2128
787 0) echo "no pid found" ;;
794 pubip
() { curl
-4s https
://icanhazip.com
; }
795 pubip6
() { curl
-6s https
://icanhazip.com
; }
796 whatismyip
() { pubip
; }
801 # -t = print pronunciation
803 for (( i
=0; i
<10; i
++ )); do
804 shuf
-n3 /usr
/share
/hunspell
/en_US.dic |
sed 's,/.*,,' |
paste -sd .
-
810 # -M CLN = use Caps, Lowercase, Numbers
812 # -a 1 = use random instead of pronounceable algorithm
813 apg
-m 50 -x 70 -n 1 -a 1 -M CLN
817 q
() { # start / launch a program in the backround and redir output to null
821 # shellcheck disable=SC2120
823 history -a # save history
825 # i had this redir, not sure why
826 # exit "$@" 2>/dev/null
830 # rsync, root is required to keep permissions right.
831 # rsync --archive --human-readable --verbose --itemize-changes --checksum \(-ahvic\) \
832 # --no-times --delete
833 # basically, make an exact copy, use checksums instead of file times to be more accurate
834 rsync
-ahvic --delete "$@"
837 # like rlu, but dont delete files on the target end which
838 # do not exist on the original end.
841 complete
-F _rsync
-o nospace rld rl rlt
844 # rl without preserving modification time.
845 rsync
-ahvic --delete --no-t "$@"
848 rlu
() { # [OPTS] HOST PATH
849 # eg. rlu -opts frodo /testpath
850 # relative paths will expanded with readlink -f.
851 opts
=("${@:1:$#-2}") # 1 to last -2
852 path
="${*:$#}" # last
853 host="${*:$#-1:1}" # last -1
854 if [[ $path == .
* ]]; then
855 path
=$
(readlink
-f $path)
857 # rync here uses checksum instead of time so we dont mess with
858 # unison relying on time as much. g is for group, same reason
859 # to keep up with unison.
860 s rsync
-rlpchviog --relative "${opts[@]}" "$path" "root@$host:/";
864 ssh fencepost
head -n 300 /gd
/gnuorg
/EventAndTravelInfo
/rms-current-trips.txt |
less
869 # I use a function because otherwise we cant use in a script,
870 # cant assign to variable.
872 # note: gksudo is recommended for X apps because it does not set the
873 # home directory to the same, and thus apps writing to ~ fuck things up
874 # with root owned files.
876 if [[ $EUID != 0 ||
$1 == -* ]]; then
877 SUDOD
="$PWD" sudo
-i "$@"
883 safe_rename
() { # warn and dont rename if file exists.
884 # mv -n exists, but it\'s silent
885 if [[ $# != 2 ]]; then
886 echo safe_rename error
: $# args
, need
2 >2
889 if [[ $1 != "$2" ]]; then # yes, we want to silently ignore this
890 if [[ -e $2 ||
-L $2 ]]; then
891 echo "Cannot rename $1 to $2 as it already exists."
899 sb
() { # sudo bash -c
900 # use sb instead of s is for sudo redirections,
901 # eg. sb 'echo "ok fine" > /etc/file'
905 complete
-F _root_command s sb
909 local s
; [[ $EUID != 0 ]] && s
=s
910 if type -p systemctl
&>/dev
/null
; then
916 # like restart, but do nothing if its not already started
919 if [[ $
(s systemctl
--no-pager show
-p ActiveState
$service ) == ActiveState
=active
]]; then
920 systemctl restart
$service
924 setini
() { # set a value in a .ini style file
925 key
="$1" value
="$2" section
="$3" file="$4"
926 if [[ -s $file ]]; then
927 sed -ri -f - "$file" <<EOF
928 # remove existing keys
929 / *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d}
931 /^\s*\[$section\]/a $key=$value
932 # from section to eof, do nothing
933 /^\s*\[$section\]/,\$b
934 # on the last line, if we haven't found section yet, add section and key
948 ser restart
$service ||
return 1
949 if type -p systemctl
&>/dev
/null
; then
955 systemctl list-unit-files | rg
"$@"
960 # 2086: unquoted $var
961 # 2046: unquoted $(cmd)
962 # 2068: Double quote array expansions to avoid re-splitting elements.
963 # 2119: Functions with optional args get bad warnings when none are passed.
964 # 2033: too many false positives for thing that will never work, passing shell function to find.
965 # i had -x as an arg, but debian testing(stretch) doesn\'t support it
966 shellcheck
-x -e 2086,2046,2068,2119,2033 "$@"
967 # had this before. not sure what it is 2119
972 # log with script. timing is $1.t and script is $1.s
973 # -l to save to ~/typescripts/
974 # -t to add a timestamp to the filenames
975 local logdir do_stamp arg_base
976 (( $# >= 1 )) ||
{ echo "arguments wrong"; return 1; }
979 while getopts "lt" option
982 l
) arg_base
=$logdir ;;
986 shift $
((OPTIND
- 1))
988 [[ -e $logdir ]] || mkdir
-p $logdir
989 $do_stamp && arg_base
+=$
(date +%F.
%T
%z
)
990 script -t $arg_base.s
2> $arg_base.t
992 splay
() { # script replay
993 #logRoot="$HOME/typescripts/"
994 #scriptreplay "$logRoot$1.t" "$logRoot$1.s"
995 scriptreplay
"$1.t" "$1.s"
999 # sudo redo. be aware, this command may not work right on strange distros or earlier software
1000 if [[ $# == 0 ]]; then
1001 sudo
-E bash
-c -l "$(history -p '!!')"
1003 echo this
command redos last
history item. no argument is accepted
1008 # with -ll, less secure but faster.
1009 command srm
-ll "$@"
1014 ssh $1 /tmp
/${2##*/} $
(printf "%q\n" "${@:2}")
1026 tclock
() { # terminal clock
1031 # this goes to full width
1032 #len=${1:-$((COLUMNS -7))}
1035 if (( x
== len
)); then
1037 d
="$(date +%l:%_M) "
1040 d
=$
(date +%l
:%M
:%_S
)
1044 for ((i
=0; i
<x
; i
++)); do
1045 if (( i
% 6 )); then
1063 # test existence / exists
1066 [[ -e "$x" ||
-L "$x" ]] || ret
=1
1072 tx
() { # toggle set -x, and the prompt so it doesnt spam
1073 if [[ $
- == *x
* ]]; then
1075 PROMPT_COMMAND
=prompt-command
1076 # disabled due to issue on stretch, running ll we get error. something
1077 # about the DEBUG trap is broken
1078 # if [[ $TERM == *(screen*|xterm*|rxvt*) ]]; then
1079 # trap 'settitle "$BASH_COMMAND"' DEBUG
1082 # normally, i would just execute these commands in the function.
1083 # however, DEBUG is not inherited, so we need to run it outside a function.
1084 # And we want to run set -x afterwards to avoid spam, so we cram everything
1085 # in here, and then it will run after this function is done.
1086 #PROMPT_COMMAND='trap DEBUG; unset PROMPT_COMMAND; PS1="\w \$ "; set -x'
1088 unset PROMPT_COMMAND
1095 # show all processes in the network namespace $1.
1096 # blank entries appear to be subprocesses/threads
1100 s
find -L /proc
/[1-9]*/task
/*/ns
/net
-samefile /run
/netns
/$netns | cut
-d/ -f5 | \
1102 x
=$
(ps
-w --no-headers -p $l);
1103 if [[ $x ]]; then echo "$x"; else echo $l; fi;
1107 m
() { printf "%s\n" "$*"; "$@"; }
1111 for x
in "$@"; do virsh destroy
"$x"; virsh undefine
"$x"; done
1119 s virsh dumpxml
$vm |
sed -r "s/(<listen.*address=')([^']+)/\1$ip/" | \
1120 sed -r "s/listen='[^']+/listen='$ip/"> $t
1121 s virsh undefine
$vm
1127 vm-set-listen
$1 0.0.0.0
1132 vm-set-listen
$1 127.0.0.1
1138 # temporary variables to test colorization
1139 # some copied from gentoo /etc/bash/bashrc,
1141 # dircolors --print-database uses its own built-in database
1142 # instead of using /etc/DIR_COLORS. Try to use the external file
1143 # first to take advantage of user additions.
1144 safe_term
=${TERM//[^[:alnum:]]/?} # sanitize TERM
1146 [[ -f ~
/.dir_colors
]] && match_lhs
="${match_lhs}$(<~/.dir_colors)"
1147 [[ -f /etc
/DIR_COLORS
]] && match_lhs
="${match_lhs}$(</etc/DIR_COLORS)"
1148 [[ -z ${match_lhs} ]] \
1149 && type -P dircolors
>/dev
/null \
1150 && match_lhs
=$
(dircolors
--print-database)
1151 # test if our $TERM is in the TERM values in dircolor
1152 [[ $
'\n'${match_lhs} == *$
'\n'"TERM "${safe_term}* ]] && use_color
=true
1155 if ${use_color} && [[ $
- == *i
* ]]; then
1157 term_bold
="$(tput bold)"
1158 term_red
="$(tput setaf 1)"
1159 term_green
="$(tput setaf 2)"
1160 term_yellow
="$(tput setaf 3)"
1161 term_purple
="$(tput setaf 5)"
1162 term_nocolor
="$(tput sgr0)" # no font attributes
1164 # unused so far. commented for shellcheck
1165 # term_underl="$(tput smul)"
1166 # term_blue="$(tput setaf 4)"
1167 # term_cyan="$(tput setaf 6)"
1170 # Try to keep environment pollution down, EPA loves us.
1171 unset safe_term match_lhs use_color
1176 if [[ $
- == *i
* ]]; then
1178 # this needs to come before next ps1 stuff
1179 # this stuff needs bash 4, feb 2009,
1180 # old enough to no longer condition on $BASH_VERSION anymore
1184 if [[ $
- == *i
* ]] && [[ ! $RLC_INSIDE_EMACS ]]; then
1186 bind -m vi-command B
:shell-backward-word
1187 bind -m vi-command W
:shell-forward-word
1190 if [[ $SSH_CLIENT ||
$SUDO_USER ]]; then
1194 # emacs terminal has problems if this runs slowly,
1195 # so I've thrown a bunch of things at the wall to speed it up.
1197 local return=$?
# this MUST COME FIRST
1198 local ps_char ps_color
1200 history -a # save history
1203 0) ps_color
="$term_purple"
1206 1) ps_color
="$term_green"
1207 ps_char
="$return \\$"
1209 *) ps_color
="$term_yellow"
1210 ps_char
="$return \\$"
1213 if [[ ! -O .
]]; then # not owner
1214 if [[ -w .
]]; then # writable
1215 ps_color
="$term_bold$term_red"
1217 ps_color
="$term_bold$term_green"
1221 # faster than sourceing the file im guessing
1222 if [[ -e /dev
/shm
/iank-status
]]; then
1223 eval $
(< /dev
/shm
/iank-status
)
1225 if [[ ! $SSH_CLIENT && $MAIL_HOST != "$HOSTNAME" ]]; then
1226 ps_char
="@ $ps_char"
1228 PS1
="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$term_nocolor\] "
1230 PROMPT_COMMAND
=prompt-command
1233 if [[ $TERM == screen
* ]]; then
1234 local title_escape
="\033]..2;"
1236 local title_escape
="\033]0;"
1238 if [[ $0 != prompt-command
]]; then
1239 echo -ne "$title_escape$USER@$HOSTNAME ${PWD/#$HOME/~} "
1246 # condition from the screen man page i think.
1247 # note: duplicated in tx()
1248 # disabled. see note in tx
1249 # if [[ $TERM == *(screen*|xterm*|rxvt*) ]]; then
1250 # trap 'settitle "$BASH_COMMAND"' DEBUG
1257 # * stuff that makes sense to be at the end
1263 # shellcheck disable=SC1090
1264 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
1267 # ensure no bad programs appending to this file will have an affect