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 # Use source ~/.bashrc instead of doing bash -l when running a script
7 # so this can set extdebug and avoid the bash debugger.
8 if [[ -s /a
/bin
/errhandle
/err
]]; then
9 source /a
/bin
/errhandle
/err
10 elif [[ -s $bashrc_dir/err
]]; then
11 # shellcheck source=/a/bin/errhandle/err
12 source $bashrc_dir/err
15 # In t8, it runs clear_console for login shells by default. I don't want
16 # my console cleared. And linux ttys get cleared without this.
17 if shopt login_shell
>/dev
/null
&& [[ -e ~
/.bash_logout
]]; then
21 # if [[ -s /usr/share/bash-completion/completions/git ]]; then
22 # source /usr/share/bash-completion/completions/git
24 # if [[ -s /usr/share/bash-completion/completions/gitk ]]; then
25 # source /usr/share/bash-completion/completions/gitk
28 # for testing error catching:
44 # remove all aliases. aliases provided by the system tend to get in the way,
45 # for example, error happens if I try to define a function the same name as an alias
48 # remove gnome keyring warning messages
49 # there is probably a more proper way, but I didnt find any easily on google
50 # now using xfce+xmonad instead of vanilla xmonad, so disabling this
51 #unset GNOME_KEYRING_CONTROL
53 # use extra globing features.
55 # include .files when globbing, but ignore files name . and ..
56 # setting this also sets dotglob.
57 export GLOBIGNORE
="*/.:*/.."
59 # Useful info. see man bash.
63 # broken with bash_completion package. Saw a bug for this once. dont anymore.
64 # still broken in wheezy
65 # still buggered in latest stable from the web, version 2.1
66 # perhaps its fixed in newer git version, which fails to make for me
67 # this note is from 6-2014.
68 # still broken in flidas.
71 # make tab on an empty line do nothing
72 shopt -s no_empty_cmd_completion
74 # fix spelling errors for cd, only in interactive shell
76 # append history instead of overwritting it
78 # for compatibility, per gentoo/debian bashrc
80 # attempt to save multiline single commands as single history entries.
87 if [[ $LC_INSIDE_EMACS ]]; then
88 # EMACS is used by bash on startup, but we dont need it anymore.
89 # plus I hit a bug in a makefile which inherited it
91 export LC_INSIDE_EMACS
94 # scp completion does not work, but this doesnt fix it. todo, figure this out
95 #complete -r scp &> /dev/null
96 # todo, remote file completion fails, figure out how to turn it off
97 export NODE_DISABLE_COLORS
=1
98 # This gets rid of ugly terminal escape chars in node repl
99 # sometime, Id like to have completion working in emacs shell for node
100 # the offending chars can be found in lib/readline.js,
101 # things that do like:
102 # stream.write('\x1b[' + (x + 1) + 'G');
103 # We can remove them and keep readline, for example by doing this
105 #!/usr/bin/env nodejs
106 # var readline = require('readline');
107 # readline.cursorTo = function(a,b,c) {};
108 # readline.clearScreenDown = function(a) {};
109 # const repl = require('repl');
110 # var replServer = repl.start('');
112 # no prompt, or else readline complete seems to be confused, based
113 # on our column being different? node probably needs to send
114 # different kind of escape sequence that is not ugly. Anyways,
115 # completion doesnt work yet even with the ugly prompt, so whatever
117 export NODE_NO_READLINE
=1
121 export SSH_CONFIG_FILE_OVERRIDE
=/root
/.ssh
/confighome
123 # emacs has a different default search path than the info command. This
124 # adds the info defaults to emacs, but not the reverse, because I dun
125 # care much about the cli. The search path is only on the cli if you run
126 # "info xxx", or in emacs if you run '(info xxx)', so not that
127 # important, but might as well fix it.
129 # info info says this path is what was compiled, and its not documented
130 # anywhere. Through source grepping, i found it in filesys.h of the info
131 # source in trisquel flidas.
133 # Traling : means for emacs to add its own stuff on to the end.
135 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
:.
:
137 # for openwrt system that has no stty, this is easier than
138 # guarding every time i use it.
139 if ! type -p stty
>/dev
/null
; then
144 if [[ $
- == *i
* ]]; then
145 # for readline-complete.el
146 if [[ $LC_INSIDE_EMACS ]]; then
147 # all for readline-complete.el
149 bind 'set horizontal-scroll-mode on'
150 bind 'set print-completions-horizontally on'
151 bind '"\C-i": self-insert'
154 if [[ $KONSOLE_PROFILE_NAME ]]; then
158 if [[ $TERM == alacritty
&& ! -e /usr
/share
/terminfo
/a
/alacritty
]]; then
159 # todo: we should try installing the alacritty terminfo if it is not found
160 # https://github.com/alacritty/alacritty/issues/2838
165 # todo: not sure this works in sakura
167 #bind "\C-w": kill-region
168 # sakura == xterm-256color
170 if [[ $TERM == xterm
* ]]; then
171 # control + arrow keys. for other terminals, see http://unix.stackexchange.com/questions/10806/how-to-change-previous-next-word-shortcut-in-bash
172 bind '"\e[1;5C": shell-forward-word' 2>/dev
/null
173 bind '"\e[1;5D": shell-backward-word' 2>/dev
/null
175 # make ctrl-backspace work. for konsole, i fixed it through
176 # /home/iank/.local/share/konsole/default.keytab
178 bind '"\eOc": shell-forward-word'
179 bind '"\eOd": shell-backward-word'
181 # i cant remember why i did this, probably to free up some keys to bind
182 # to other things in bash.
183 # other than C-c and C-z, the rest defined by stty -a are, at least in
184 # gnome-terminal, overridden by bash, or disabled by the system
185 stty lnext undef stop undef start undef
190 export BC_LINE_LENGTH
=0
193 export PROFILE_TASKS_TASK_OUTPUT_LIMIT
=100
195 # note, if I use a machine I dont want files readable by all users, set
196 # umask 077 # If fewer than 4 digits are entered, leading zeros are assumed
198 # i for insensitive. the rest from
199 # X means dont remove the current screenworth of output upon exit
200 # R means to show colors n things
202 export SYSTEMD_LESS
=$LESS
204 export NNN_COLORS
=2136
206 export SL_FILES_DIR
=/b
/ds
/sl
/.iank
207 export SL_INFO_DIR
=/p
/sshinfo
212 if [[ -s $bashrc_dir/path-add-function
]]; then
213 source $bashrc_dir/path-add-function
214 if [[ $SSH_CLIENT ]]; then
215 # [[ -d /home/iank/.iank/e/e ]] mounts it unnecessarily, so use this.
216 if grep -qF /home
/iank
/.iank
/e
/e
/etc
/auto.iank
/etc
/exports
&>/dev
/null
; then
217 export EMACSDIR
=/home
/iank
/.iank
/e
/e
222 # if someone exported $SOE (stop on error), catch errors.
224 # Note, on debian this results in the following warning when in ssh,
225 # hich I haven't figured out how to fix. It doesn't happen if we source
226 # after the shell has started
228 # bash: /usr/share/bashdb/bashdb-main.inc: No such file or directory
229 # bash: warning: cannot start debugger; debugging mode disabled
231 if [[ -e /a
/bin
/errhandle
/err
]]; then
232 source /a
/bin
/errhandle
/err
236 # based on readme.debian. dunno if this will break on other distros.
237 if [[ -s /usr
/share
/wcd
/wcd-include.sh
]]; then
238 source /usr
/share
/wcd
/wcd-include.sh
241 if [[ -s /a
/bin
/small-misc-bash
/ll-function
]]; then
242 source /a
/bin
/small-misc-bash
/ll-function
243 elif [[ -s $bashrc_dir/ll-function
]]; then
244 # shellcheck source=/a/bin/small-misc-bash/ll-function
245 source $bashrc_dir/ll-function
252 ccomp
() { # copy completion
256 if ! c
=$
(complete
-p $src 2>/dev
/null
); then
257 _completion_loader
$src &>/dev
/null ||
:
258 c
=$
(complete
-p $src 2>/dev
/null
) ||
return 0
269 ....
() { c ..
/..
/..
; }
270 .....
() { c ..
/..
/..
/..
; }
271 ......
() { c ..
/..
/..
/..
/..
; }
276 path
=$
(readlink
-e "$f")
277 echo "cat >$path <<'EOF'"
284 # file cut copy and paste, like the text buffers :)
285 # I havnt tested these.
286 _fbufferinit
() { # internal use
287 ! [[ $my_f_tempdir ]] && my_f_tempdir
=$
(mktemp
-d)
288 rm -rf "${my_f_tempdir:?}"/*
292 cp "$@" "$my_f_tempdir"/
296 mv "$@" "$my_f_tempdir"/
298 fpst
() { # file paste
299 [[ $2 ]] && { echo too many arguments
; return 1; }
301 cp "$my_f_tempdir"/* "$target"
306 read -r host ip port
< <(timeout
-s 9 2 ssh -oBatchMode=yes -oControlMaster=no
-oControlPath=/ -v $1 |
& sed -rn "s/debug1: Connecting to ([^ ]+) \[([^\]*)] port ([0-9]+).*/\1 \2 \3/p" ||
[[ $?
== 124 ]])
308 echo "khfix: ssh failed"
311 if [[ $port != 22 ]]; then
312 ip_entry
="[$ip]:$port"
313 host_entry
="[$host]:$port"
318 if [[ $host != $ip ]]; then
319 ssh-keygen
-R "$host_entry" -f $
(readlink
-f ~
/.ssh
/known_hosts
)
321 echo "khfix: removing key for $ip_entry"
322 ssh-keygen
-R "$ip_entry" -f $
(readlink
-f ~
/.ssh
/known_hosts
)
325 khfix
() { # known hosts fix
326 _khfix_common
"$@" ||
return 1
336 x
=$
(readlink
-nf "${1:-$PWD}")
337 # yes, its kinda dumb that xclip/xsel cant do this in one invocation
338 echo -n "$x" | xclip
-selection clipboard
342 # a1 = awk {print $1}
343 for field
in {1.
.20}; do
344 eval a
$field"() { awk '{print \$$field}'; }"
347 for num
in {1.
.9}; do
348 eval h
$num"() { head -n$num; }"
359 if type -p wcd
&>/dev
/null
; then
360 if [[ $LC_INSIDE_EMACS ]]; then
361 c
() { wcd
-c -z 50 -o "$@"; }
363 # lets see what the fancy terminal does from time to time
364 c
() { wcd
-c -z 50 "$@"; }
371 c4
() { c
/var
/log
/exim4
; }
373 caa
() { git commit
--amend --no-edit -a; }
384 # shellcheck disable=SC2033
385 find -L "$@" -type f
-not \
( -name .svn
-prune -o -name .git
-prune \
386 -o -name .hg
-prune -o -name .editor-backups
-prune \
387 -o -name .undo-tree-history
-prune \
) \
388 -exec bash
-c '. ~/.bashrc; hr; echo "$1"; hr; cat "$1"' _
{} \
; 2>/dev
/null
393 calc
() { echo "scale=3; $*" |
bc -l; }
394 # no having to type quotes, but also no command history:
398 echo "scale=3; $x" |
bc -l
405 ccat
() { # config cat. see a config without extra lines.
406 grep '^\s*[^;[:space:]#]' "$@" ||
[[ $?
== 1 ]]
412 # dev/pts needed for pacman signature check
413 for d
in dev proc sys dev
/pts
; do
415 if ! mountpoint
$d &>/dev
/null
; then
416 s mount
-o bind /$d $d
423 # join options which are continued to multiples lines onto one line
425 while IFS
= read -r line
; do
426 # remove leading spaces/tabs. assumes extglob
427 if [[ $line == "[ ]*" ]]; then
433 elif [[ $line == *=* ]]; then
434 echo "$pastline" >> "$2"
437 pastline
="$pastline $line"
439 done < <(grep -vE '^([ \t]*#|^[ \t]*$)' "$1")
440 echo "$pastline" >> "$2"
445 # setup for format of postfix, eg:
448 local pastline unified f1 f2
452 _cdiff-prep
"$1" "$f1"
453 _cdiff-prep
"$2" "$f2"
454 cat "$f1" "$f2" |
grep -Po '^[^=]+=' |
sort |
uniq > "$unified"
455 while IFS
= read -r line
; do
456 # the default bright red / blue doesnt work in emacs shell
457 dwdiff
-cblue,red
-A best
-d " ," <(grep "^$line" "$f1" ||
echo ) <(grep "^$line" "$f2" ||
echo ) | colordiff
465 inotifywait
-m "$dir" -e create
-e moved_to |
466 # shellcheck disable=SC2030
467 while read -r filedir _
file; do
470 calc $
((SECONDS
- start
)) / 60
476 # shellcheck disable=SC2032
478 # makes it so chown -R symlink affects the symlink and its target.
479 if [[ $1 == -R ]]; then
481 command chown
-h "$@"
482 command chown
-R "$@"
493 # choose recent directory. cl = cd list
497 d
() { builtin bg "$@"; }
501 diff --strip-trailing-cr -w "$@" # diff content
509 safe_rename
"$x" "$y"
514 command dig +nostats
+nocmd
"$@"
516 # Output with sections sorted, and removal of query id, so 2 dig outputs can be diffed.
520 dig +nordflag
"$@" |
sed -r 's/^(;; ->>HEADER<<-.*), id: .*/\1/' |
while read -r l
; do
521 if [[ $l == [^\
;]* ]]; then
525 printf "%s" "$sec" |
sort
533 # compare digs to the 2 servers
534 # usage: digdiff @server1 @server2 DIG_ARGS
535 # note: only the soa master nameserver will respond with
536 # ra "recursive answer" flag. That difference is meaningless afaik.
543 digsort
$s1 "$@" |
tee /tmp
/digdiff
544 diff -u /tmp
/digdiff
<(digsort
$s2 "$@")
548 date "+%A, %B %d, %r" "$@"
552 dus
() { # du, sorted, default arg of
553 du
-sh ${@:-*} |
sort -h
566 printf "%qEOL\n" "${arg}"
567 printf "%s" "${arg}" |
& hexdump -C
570 # echo vars. print var including escapes, etc
576 printf "%qEOL\n" "${!arg}"
577 printf "%s" "${!arg}" |
& hexdump -C
582 [[ ${#@} == 2 ]] ||
{ echo "error: ediff requires 2 arguments"; return 1; }
583 emacs
--eval "(ediff-files \"$1\" \"$2\")"
588 tail -F /var
/log
/exim
4/mainlog
-n 200 "$@"
592 # print exim old pids
594 local configtime pid piduptime now daemonpid
595 printf -v now
'%(%s)T' -1
596 configtime
=$
(stat
-c%Y
/var
/lib
/exim
4/config.autogenerated
)
597 if [[ -s /run
/exim
4/exim.pid
]]; then
598 daemonpid
=$
(cat /run
/exim
4/exim.pid
)
600 for pid
in $
(pgrep
-f '^/usr/sbin/exim4( |$)'); do
601 # the daemonpid gets reexeced on HUP (service reloads), keeping its same old timestamp
602 if [[ $pid == $daemonpid ]]; then
605 piduptime
=$
(awk -v ticks
="$(getconf CLK_TCK)" 'NR==1 { now=$1; next } END { printf "%9.0f\n", now - ($20/ticks) }' /proc
/uptime RS
=')' /proc
/$pid/stat
) ||
: # sometimes pids disappear pretty fast
606 if (( configtime
> now
- piduptime
)); then
612 # exim tail but only watch lines from new pids
615 for pid
in $
(eoldpids
); do
618 if [[ $oldpids ]]; then
619 etail |
awk '$3 !~ /^\[('"${oldpids%|}"')\]$/'
624 # exim watch as old pids go away
626 local configtime pid piduptime now
631 oldpids
=($
(eoldpids
))
632 if (( ! ${#oldpids[@]} )); then
635 # print the date every 20 iterations
636 if (( ! count
% 20 )); then
640 ps
-f -p "${oldpids[*]}"
646 less /var
/log
/exim
4/mainlog
650 exiqgrep
-i -o 60 |
while read -r i
; do
653 hlm exigrep
$i /var
/log
/exim
4/mainlog |
cat ||
:
657 exiqgrep
-i |
xargs exim
-Mrm
662 mkdir
-p /tmp
/edev
/etc
663 cp -ra /etc
/exim4
/tmp
/edev
/etc
664 cp -ra /etc
/alias* /tmp
/edev
/etc
665 find /tmp
/edev
/etc
/exim4
-type f
-execdir sed -i "s,/etc/,/tmp/edev/etc/,g" '{}' +
669 update-exim4.conf
-d /tmp
/edev
/etc
/exim4
-o /tmp
/edev
/e.conf
674 # shellcheck disable=SC2032
681 # find array. make an array of file names found by find into $x
682 # argument: find arguments
683 # return: find results in an array $x
684 while read -rd ''; do
686 done < <(find "$@" -print0);
689 faf
() { # find all files. use -L to follow symlinks
690 find "$@" -not \
( -name .svn
-prune -o -name .git
-prune \
691 -o -name .hg
-prune -o -name .editor-backups
-prune \
692 -o -name .undo-tree-history
-prune \
) -type f
2>/dev
/null
698 sudo mailq |gr frozen|
awk '{print $3}' |
while read -r id
; do
704 echo -e '\n\n##############################\n'
705 done |
tee -a /tmp
/frozen
709 while read -r line
; do
710 printf '%s\n' "$line"
711 ids
+=($
(printf '%s\n' "$line" |gr frozen|
awk '{print $3}'))
713 echo "sleeping for 2 in case you change your mind"
715 sudo exim
-Mrm "${ids[@]}"
719 # like -e for functions. returns on error.
720 # at the end of the function, disable with:
722 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
723 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"
729 local help="Usage: getdir [--help] PATH
730 Output the directory of PATH, or just PATH if it is a directory."
731 if [[ $1 == --help ]]; then
735 if [[ $# -ne 1 ]]; then
736 echo "getdir error: expected 1 argument, got $#"
743 dir
="$(dirname "$1")"
744 if [[ -d $dir ]]; then
747 echo "getdir error: directory does not exist"
753 git_empty_branch
() { # start an empty git branch. carefull, it deletes untracked files.
754 [[ $# == 1 ]] ||
{ echo 'need a branch name!'; return 1;}
756 root
=$
(gitroot
) ||
return 1 # function to set gitroot
758 git symbolic-ref HEAD refs
/heads
/$1
763 # shellcheck disable=SC2120
765 local help="Usage: gitroot [--help]
766 Print the full path to the root of the current git repo
768 Handles being within a .git directory, unlike git rev-parse --show-toplevel,
769 and works in older versions of git which did not have that."
770 if [[ $1 == --help ]]; then
775 p
=$
(git rev-parse
--git-dir) ||
{ echo "error: not in a git repo" ; return 1; }
776 [[ $p != /* ]] && p
=$PWD
782 # todo: patch emacs so it will look elsewhere. this is kinda sad:
783 # https://emacs.stackexchange.com/questions/4253/how-to-start-emacs-with-a-custom-user-emacs-directory
787 if [[ $EMACSDIR ]]; then
788 path-add
"$EMACSDIR/lib-src" "$EMACSDIR/src"
791 if [[ $DISPLAY ]]; then
795 if (( $# == 0 )); then
798 # duplicate -c, but oh well
799 if ! pgrep
-u $EUID emacsclient
; then
800 if (( $# == 0 )) && type -p gdb
&>/dev
/null
; then
806 if [[ $EMACSDIR ]]; then
807 # Alter the path here, otherwise the nfs mount gets triggered on the
808 # first path lookup when emacs is not being used.
809 PATH
="$EMACSDIR/lib-src:$EMACSDIR/src:$PATH" EHOME
=$HOME HOME
=$EMACSDIR m emacsclient
-a "" $args "$@"
812 # due to a bug, we cant debug from the start unless we get a new gdb
813 # https://sourceware.org/bugzilla/show_bug.cgi?id=24454
814 # m gdb -ex="set follow-fork-mode child" -ex=r -ex=quit --args emacs --daemon
815 m emacsclient
-a "" $args "$@"
817 cd /a
/opt
/emacs-$
(distro-name
)$
(distro-num
)
818 s gdb
-p $
(pgrep
-f 'emacs --daemon') -ex c
821 m emacsclient
-a "" $args "$@"
826 # force terminal version
832 # quit will prompt if the program crashes.
833 gdb
-ex=r
-ex=quit
--args emacs
"$@"; r
;
837 # kill the emacs daemon
842 grep -iIP --color=auto
"$@" ||
return $?
844 grr
() { # grep recursive
845 # Don't return 1 on nonmatch because this is meant to be
846 # interactive, not in a conditional.
847 if [[ ${#@} == 1 ]]; then
848 grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -riIP --color=auto
"$@" . ||
[[ $?
== 1 ]]
850 grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -riIP --color=auto
"$@" ||
[[ $?
== 1 ]]
858 hr
() { # horizontal row. used to break up output
859 printf "$(tput setaf 5 2>/dev/null ||:)â–ˆ$(tput sgr0 2>/dev/null||:)%.0s" $
(eval echo "{1..${COLUMNS:-60}}")
864 local col input_len
=0
866 input_len
=$
((input_len
+ 1 + ${#arg}))
868 col=$
((60 - input_len
))
869 printf "\e[1;97;41m%s" "$*"
870 if (( col > 0 )); then
871 printf "\e[1;97;41m \e[0m%.0s" $
(eval echo "{1..${col}}")
875 hlm
() { hl
"$*"; "$@"; }
877 hrcat
() { local f
; for f
; do [[ -f $f ]] ||
continue; hr
; echo "$f"; cat "$f"; done }
880 # get latest hub and run it
881 # main command to use:
882 # hub pull-request --no-edit
883 # --no-edit means to use the first commit\'s message as the pull request message.
884 # If that fails, try doing
885 # hub pull-request --no-edit -b UPSTREAM_OWNER:branch
886 # where branch is usually master. it does the pr against your current branch.
888 # On first use, you input username/pass and it gets an oath token so you dont have to repeat
889 # it\'s at ~/.config/hub
891 local up uptar updir p
892 p
=/github
/hub
/releases
/
893 up
=https
://github.com
/$
(curl
-s https
://github.com
$p|
grep -o $p'download/[^/]*/hub-linux-amd64[^"]*' |
head -n1)
896 if [[ ! -e /a
/opt
/$updir ]]; then
897 rm -rf /a
/opt
/hub-linux-amd64
*
899 tar -C /a
/opt
-zxf /a
/opt
/$uptar
902 if ! which hub
&>/dev
/null
; then
903 sudo
/a
/opt
/$updir/install
906 # save token across computers
907 if [[ ! -L ~
/.config
/hub
]]; then
908 if [[ -e ~
/.config
/hub
]]; then
909 mv ~
/.config
/hub
/p
/c
/subdir_files
/.config
/
911 if [[ -e /p
/c
/subdir_files
/.config
/hub
]]; then
929 find -L .
-not \
( -name .svn
-prune -o -name .git
-prune \
930 -o -name .hg
-prune -o -name .editor-backups
-prune \
931 -o -name .undo-tree-history
-prune \
) -iname "*$**" 2>/dev
/null
935 # insensitive find directory
936 find -L .
-type d
-not \
( -name .svn
-prune -o -name .git
-prune \
937 -o -name .hg
-prune -o -name .editor-backups
-prune \
938 -o -name .undo-tree-history
-prune \
) -iname "*$**" 2>/dev
/null
943 sudo iptables
-A INPUT
-s $1 -j DROP
948 grep -Il "" "$@" &>/dev
/null
952 journalctl
-n 10000 -f "$@"
954 jr
() { journalctl
"$@" ; }
955 jrf
() { journalctl
-f "$@" ; }
957 journalctl
-u exim4 _SYSTEMD_INVOCATION_ID
=$
(systemctl show
-p InvocationID
--value $1)
961 if [[ $PWD == /[iap
] ]]; then
962 command ls -A --color=auto
-I lost
+found
"$@"
964 command ls -A --color=auto
"$@"
968 lcn
() { locate -i "*$**"; }
970 lg
() { LC_COLLATE
=C.UTF-8 ll
--group-directories-first "$@"; }
972 lt
() { ll
-tr "$@"; }
974 lld
() { ll
-d "$@"; }
976 ccomp
ls l lg lt lld ll
982 for dirs in false true
; do
986 # reverse the order to rename the nested dirs first.
987 # note: 0 element is the dir itself
988 for ((i
=${#all[@]}-1; i
>=1; i--
)); do
990 if $dirs && [[ -d $a ]]; then
991 # e dirs low "$a" # debug
993 elif ! $dirs && [[ ! -d $a && -e $a ]]; then
995 # e not dirs low "$a" # debug
1000 # just rename all the top level args on the second pass
1002 # e final dirs low "$f" # debug
1009 low
() { # make filenames lowercase, remove bad chars
1012 arg
="${arg%%+(/)}" # remove trailing slashes. assumes we have extglob on.
1014 if (( ${#dir} == ${#arg} )); then
1018 new
="${f,,}" # downcase
1019 new
="${new//[^[:alnum:]._-]/_}" # sub bad chars
1020 new
="${new#"${new%%[[:alnum:]]*}"}" # remove leading/trailing non-alnum
1021 new
="${new%"${new##*[[:alnum:]]}"}"
1022 # remove bad underscores, like __ and _._
1023 new
=$
(echo $new |
sed -r 's/__+/_/g;s/_+([.-])|([.-])_+/\1/g')
1024 safe_rename
"$dir/$f" "$dir/$new" ||
return 1
1029 lower
() { # make first letter of filenames lowercase.
1032 if [[ ${x::1} == [A-Z
] ]]; then
1033 y
=$
(tr '[:upper:]' '[:lower:]' <<<"${x::1}")"${x:1}"
1034 safe_rename
"$x" "$y" ||
return 1
1040 k
() { # history search
1041 grep -iP --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
tail -n 80 ||
[[ $?
== 1 ]];
1043 ks
() { # history search
1044 grep -P --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
uniq ||
[[ $?
== 1 ]];
1050 # show make targets, via http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make
1051 make -qp |
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
1064 mkt
() { # mkdir and touch file
1066 mkdir
-p "$(dirname "$path")"
1070 # shellcheck disable=SC2032
1071 mkdir
() { command mkdir
-p "$@"; }
1074 # https://github.com/HenriWahl/Nagstamon/issues/357
1075 if ! pgrep
-f /usr
/lib
/notification-daemon
/notification-daemon
>/dev
/null
; then
1076 /usr
/lib
/notification-daemon
/notification-daemon
&
1078 /usr
/bin
/nagstamon
&
1082 s nmtui-connect
"$@"
1086 # shellcheck disable=SC2024
1087 sudo
tee -a /var
/log
/exim
4/paniclog-archive
</var
/log
/exim
4/paniclog
; sudo truncate
-s0 /var
/log
/exim
4/paniclog
1090 p8
() { ping "$@" 8.8.8.8; }
1091 p6
() { ping6
"$@" 2001:4860:4860::8888; }
1093 pkx
() { # package extract
1094 local pkg cached tmp f
1097 # shellcheck disable=SC2012
1098 cached
=$
(ls -t /var
/cache
/apt
/archives
/$pkg* |
tail -n1 2>/dev
/null
) ||
:
1099 if [[ $cached ]]; then
1102 aptitude download
$pkg ||
return 1
1104 tmp
=(*); f
=${tmp[0]} # only 1 expected
1112 pid
=($
(pgrep
-f "$*"))
1115 # shellcheck disable=SC2128
1121 0) echo "no pid found" ;;
1130 help="Usage: psg [--help] GREP_ARGS
1131 grep ps and output in a nice format"
1132 if [[ $1 == --help ]]; then
1137 # final grep is because some commands tend to have a lot of trailing spaces
1138 y
=$
(echo "$x" |
grep -iP "$@" |
grep -o '.*[^ ]') ||
:
1140 echo "$x" |
head -n 1 ||
[[ $?
== 141 ]]
1145 pubip
() { curl
-4s https
://icanhazip.com
; }
1146 pubip6
() { curl
-6s https
://icanhazip.com
; }
1147 whatismyip
() { pubip
; }
1150 q
() { # start / launch a program in the backround and redir output to null
1154 # shellcheck disable=SC2120
1156 if [[ $HISTFILE ]]; then
1157 history -a # save history
1159 trap ERR
# this avoids a segfault
1161 # i had this redir, not sure why
1162 # exit "$@" 2>/dev/null
1165 # scp is insecure and deprecated.
1167 rsync
--inplace "$@"
1171 # available high ports are 1024-65535,
1172 # but lets skip things that are more likely to be in use
1175 print(secrets.SystemRandom().randrange(10002,65500))
1190 # rsync, root is required to keep permissions right.
1191 # rsync --archive --human-readable --verbose --itemize-changes --checksum \(-ahvic\) \
1192 # --no-times --delete
1193 # basically, make an exact copy, use checksums instead of file times to be more accurate
1194 rsync
-ahvic --delete "$@"
1197 # like rlu, but dont delete files on the target end which
1198 # do not exist on the original end.
1202 # rl without preserving modification time.
1203 rsync
-ahvic --delete --no-t "$@"
1205 rsu
() { # [OPTS] HOST PATH
1206 # eg. rlu -opts frodo /testpath
1207 # relative paths will expanded with readlink -f.
1208 opts
=("${@:1:$#-2}") # 1 to last -2
1209 path
="${*:$#}" # last
1210 host="${*:$#-1:1}" # last -1
1211 if [[ $path == .
* ]]; then
1212 path
=$
(readlink
-f $path)
1214 # rync here uses checksum instead of time so we dont mess with
1215 # unison relying on time as much. g is for group, same reason
1216 # to keep up with unison.
1217 m s rsync
-rlpchviog --relative "${opts[@]}" "$path" "root@$host:/";
1219 ccomp rsync rsd rsa rst rsu
1223 if [[ $
(systemctl is-active nscd ||
:) != inactive
]]; then
1228 hr
; s ss
-lpn 'sport = 53'
1229 if systemctl is-enabled dnsmasq
&>/dev
/null ||
[[ $
(systemctl is-active dnsmasq ||
:) != inactive
]]; then
1230 # this will fail is dnsmasq is failed
1231 hr
; m ser status dnsmasq |
cat ||
:
1233 hr
; echo $f:; ccat
$f
1234 hr
; m grr
'^ *(servers-file|server) *=|^ *no-resolv *$' /etc
/dnsmasq.conf
/etc
/dnsmasq.d
1235 f
=/etc
/dnsmasq-servers.conf
1236 hr
; echo $f:; ccat
$f
1239 echo /etc
/nsswitch.conf
:
1240 grep '^ *hosts:' /etc
/nsswitch.conf
1241 if systemctl is-enabled systemd-resolved
&>/dev
/null ||
[[ $
(systemctl is-active systemd-resolved ||
:) != inactive
]]; then
1242 hr
; m ser status systemd-resolved |
cat ||
:
1243 hr
; m systemd-resolve
--status |
cat
1251 if [[ $
(systemctl is-active nscd ||
:) != inactive
]]; then
1255 m sudo nscd
-i hosts
1257 if [[ $
(systemctl is-active dnsmasq ||
:) != inactive
]]; then
1258 m sudo systemctl restart dnsmasq
1260 if [[ $
(systemctl is-active systemd-resolved ||
:) != inactive
]]; then
1261 m sudo systemctl restart systemd-resolved
1263 if type -P resolvectl
&>/dev
/null
; then
1264 resolvectl flush-caches
1269 ssh fencepost
head -n 300 /gd
/gnuorg
/EventAndTravelInfo
/rms-current-trips.txt |
less
1274 # I use a function because otherwise we cant use in a script,
1275 # cant assign to variable.
1277 # note: gksudo is recommended for X apps because it does not set the
1278 # home directory to the same, and thus apps writing to ~ fuck things up
1279 # with root owned files.
1281 if [[ $EUID != 0 ||
$1 == -* ]]; then
1282 # shellcheck disable=SC2034
1283 SUDOD
="$PWD" command sudo
-i "$@"
1289 sb
() { # sudo bash -c
1290 # use sb instead of s is for sudo redirections,
1291 # eg. sb 'echo "ok fine" > /etc/file'
1292 # shellcheck disable=SC2034
1294 sudo
-i bash
-c "$@"
1298 safe_rename
() { # warn and dont rename if file exists.
1299 # mv -n exists, but it\'s silent
1300 if [[ $# != 2 ]]; then
1301 echo safe_rename error
: $# args
, need
2 >2
1304 if [[ $1 != "$2" ]]; then # yes, we want to silently ignore this
1305 if [[ -e $2 ||
-L $2 ]]; then
1306 echo "Cannot rename $1 to $2 as it already exists."
1316 sudo
dd status
=none of
="$1"
1320 if type -p systemctl
&>/dev
/null
; then
1326 seru
() { systemctl
--user "$@"; }
1327 # like restart, but do nothing if its not already started
1330 if [[ $
(s systemctl
--no-pager show
-p ActiveState
$service ) == ActiveState
=active
]]; then
1331 systemctl restart
$service
1335 setini
() { # set a value in a .ini style file
1336 key
="$1" value
="$2" section
="$3" file="$4"
1337 if [[ -s $file ]]; then
1338 sed -ri -f - "$file" <<EOF
1339 # remove existing keys
1340 / *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d}
1342 /^\s*\[$section\]/a $key=$value
1343 # from section to eof, do nothing
1344 /^\s*\[$section\]/,\$b
1345 # on the last line, if we haven't found section yet, add section and key
1357 sgo
() { # service go
1359 ser restart
$service ||
return 1
1360 if type -p systemctl
&>/dev
/null
; then
1366 # ignore services that dont exist
1367 if systemctl
cat $service &>/dev
/null
; then
1369 ser disable
$service
1375 systemctl list-unit-files | rg
"$@"
1380 # 2029: "unescaped, this expands on the client side." yes, I know how ssh works
1381 # 2164: "Use 'cd ... || exit' or 'cd ... || return' in case cd fails." i have automatic error handling
1382 # 2086: unquoted $var
1383 # 2046: unquoted $(cmd)
1384 # 2068: Double quote array expansions to avoid re-splitting elements.
1385 # 2119: Functions with optional args get bad warnings when none are passed.
1386 # 2033: too many false positives for thing that will never work, passing shell function to find.
1387 # i had -x as an arg, but debian testing(stretch) doesn\'t support it
1388 shellcheck
-x -e 2029,2164,2086,2046,2068,2119,2033 "$@" ||
return $?
1389 # had this before. not sure what it is 2119
1393 # sl: ssh, but firsh rsync our bashrc and related files to a special
1394 # directory on the remote host if needed.
1396 # Some environment variables and files need to be setup for this to work
1397 # (mine are set at the beginning of this file)
1399 # SL_FILES_DIR: Environment variable. Path to folder which should at
1400 # least have a .bashrc file or symlink. This dir will be rsynced to ~ on
1401 # remote hosts (top level symlinks are resolved) unless the host already
1402 # has a $SL_FILES_DIR/.bashrc. In that case, we assume it is a host you
1403 # control and sync files to separately and already has the ~/.bashrc you
1404 # want. The remote bash will also take its .inputrc config from this
1405 # folder (default of not existing is fine). Mine looks like this:
1406 # https://iankelling.org/git/?p=distro-setup;a=tree;f=sl/.iank
1408 # SL_INFO_DIR: Environment variable. This folder stores info about what
1409 # we detected on the remote system and when we last synced. It will be created
1410 # if it does not exist. Sometimes you may want to forget about a
1411 # remote system, you can use sl --rsync, or the function for that slr
1414 # SL_TEST_CMD: Env var. Meant to be used to vary the files synced
1415 # depending on the remote host. Run this string on the remote host the
1416 # first time sl is run (or if we run slr). The result is passed to
1417 # SL_TEST_HOOK. For example,
1418 # export SL_TEST_CMD=". /etc/os-release ; echo \${VERSION//[^a-zA-Z0-9]/}"
1420 # SL_TEST_HOOK: Env var. It is run as $SL_TEST_HOOK. This can set
1421 # $SL_FILES_DIR to vary the files synced.
1423 # SL_RSYNC_ARGS: Env var. String of arguments passed to rsync. For
1424 # example to exclude files within a directory. Note, excluded
1425 # files wont be deleted on rsync, you can add --delete-excluded
1426 # to the rsync command if that is desired.
1428 # SL_SSH_ARGS: Env var. Default arguments passed to ssh.
1430 # For when ~/.bashrc is already customized on the remote server, you
1431 # might find it problematic that ~/.bashrc is sourced for ALL ssh
1432 # commands, even in scripts. This paragraph is all about that. bash
1433 # scripts dont source ~/.bashrc, but call ssh in scripts and you get
1434 # ~/.bashrc. You dont want this. .bashrc is meant for interactive shells
1435 # and if you customize it, probably has bugs from time to time. This is
1436 # bad. Here's how I fix it. I have a special condition to "return" in my
1437 # .bashrc for noninteractive ssh shells (copy that code). Then use this
1438 # function or similar that passes LC_USEBASHRC=t when sshing and I want
1439 # my bashrc. Also, I don't keep most of my bashrc in .bashrc, i source a
1440 # separate file because even if I return early on, the whole file gets
1441 # parsed which can fail if there is a syntax error.
1443 # Background on LC_USEBASHRC var (no need to read if you just want to
1444 # use this function): env variables sent across ssh are strictly
1445 # limited, but we get LC_* at least in debian based machines, so we
1446 # just make that * be something no normal program would use. Note, on
1447 # hosts that dont allow LC_* I start an inner shell with LC_USEBASHRC
1448 # set, and the inner shell also allows running a nondefault
1449 # .bashrc. This means the outer shell still ran the default .bashrc,
1450 # but that is the best we can do.
1452 local now args remote dorsync haveinfo tmpa sshinfo tmp tmp2
type info_sec force_rsync \
1453 sync_dirname testcmd extra_info testbool files_sec sl_test_cmd sl_test_hook
1454 declare -a args tmpa
1458 # ssh [-1246Antivivisectionist] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
1459 # [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-L address]
1460 # [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option]
1461 # [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] [user@]hostname
1464 # ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
1465 # [-D [bind_address:]port] [-E log_file] [-e escape_char]
1466 # [-F configfile] [-I pkcs11] [-i identity_file]
1467 # [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
1468 # [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
1469 # [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
1472 if [[ $1 == --rsync ]]; then
1477 sl_test_cmd
=$SL_TEST_CMD
1478 sl_test_hook
=$SL_TEST_HOOK
1479 sl_rsync_args
=$SL_RSYNC_ARGS
1506 # note we dont support things like -4oOption
1507 -[46AaCfGgKkMNnqsTtVvXxYy
]*)
1510 -[bcDEeFIiJLlmOopQRSWw
]*)
1511 # -oOption etc is valid
1512 if (( ${#1} >= 3 )); then
1515 args
+=("$1" "$2"); shift 2
1524 if [[ ! $remote ]]; then
1525 echo $0: error hostname required
>&2
1530 if [[ ! $SL_INFO_DIR ]]; then
1531 echo error
: missing
'$SL_INFO_DIR' env var
>&2
1538 tmpa
=($SL_INFO_DIR/???????????
"$remote")
1540 if [[ -e $sshinfo ]]; then
1541 if $force_rsync; then
1548 tmp
=${sshinfo[0]##*/}
1551 extra_info
=$
(cat $sshinfo)
1553 # we test for string to know ssh succeeded
1554 testbool
="test -e $SL_FILES_DIR/.bashrc -a -L .bashrc -a -v LC_USEBASHRC"
1555 testcmd
="if $testbool; then printf y; else printf n; fi"
1556 if ! tmp
=$
(LC_USEBASHRC
=y
command ssh "${args[@]}" "$remote" "$testcmd; $sl_test_cmd"); then
1557 echo failed sl
test. doing plain
ssh -v
1558 command ssh -v "${args[@]}" "$remote"
1560 if [[ $tmp == y
* ]]; then
1566 extra_info
="${tmp:1}"
1568 if [[ $sl_test_hook ]]; then
1569 RSYNC_RSH
="ssh ${args[*]}" $sl_test_hook "$extra_info" "$remote"
1572 if $haveinfo && [[ $type == b
]]; then
1574 read files_sec _
< <(find -L $SL_FILES_DIR -printf "%T@ %p\n" |
sort -nr ||
[[ $?
== 141 ||
${PIPESTATUS[0]} == 32 ]] )
1575 files_sec
=${files_sec%%.*}
1576 if (( files_sec
> info_sec
)); then
1582 sync_dirname
=${SL_FILES_DIR##*/}
1584 if [[ ! $SL_FILES_DIR ]]; then
1585 echo error
: missing
'$SL_FILES_DIR' env var
>&2
1590 RSYNC_RSH
="ssh ${args[*]}" m rsync
-rptL --delete $sl_rsync_args $SL_FILES_DIR "$remote":
1592 if $dorsync ||
! $haveinfo; then
1593 sshinfo
=$SL_INFO_DIR/$now$type"$remote"
1594 [[ -e $SL_INFO_DIR ]] || mkdir
-p $SL_INFO_DIR
1595 printf "%s\n" "$extra_info" >$sshinfo
1598 if [[ $type == b
]]; then
1599 if (( ${#@} )); then
1600 # Theres a couple ways to pass arguments, im not sure whats best,
1601 # but relying on bash 4.4+ escape quoting seems most reliable.
1602 command ssh "${args[@]}" "$remote" \
1603 LC_USEBASHRC
=t bash
-c '.\ '$sync_dirname'/.bashrc\;"\"\$@\""' bash
${@@Q}
1604 elif [[ ! -t 0 ]]; then
1605 # This case is when commands are being piped to ssh.
1606 # Normally, no bashrc gets sourced.
1607 # But, since we are doing all this, lets source it because we can.
1608 cat <(echo .
$sync_dirname/.bashrc
) - |
command ssh "${args[@]}" "$remote" LC_USEBASHRC
=t bash
1610 command ssh -t "${args[@]}" "$remote" LC_USEBASHRC
=t INPUTRC
=$sync_dirname/.inputrc bash
--rcfile $sync_dirname/.bashrc
1614 LC_USEBASHRC
=t
command ssh "${args[@]}" "$remote" ${@@Q}
1616 command ssh "${args[@]}" "$remote" LC_USEBASHRC
=t bash
1619 # this function inspired from https://github.com/Russell91/sshrc
1626 sl
-oControlMaster=no
-oControlPath=/ "$@"
1628 # kill off old shared socket then ssh
1630 m
ssh -O exit "$@" ||
[[ $?
== 255 ]]
1633 ccomp
ssh sl slr sss ssk
1636 if [[ $TERM == alacritty
]]; then
1637 TERM
=xterm-256color LC_USEBASHRC
=t
command ssh "$@"
1639 LC_USEBASHRC
=t
command ssh "$@"
1645 # log with script. timing is $1.t and script is $1.s
1646 # -l to save to ~/typescripts/
1647 # -t to add a timestamp to the filenames
1648 local logdir do_stamp arg_base
1649 (( $# >= 1 )) ||
{ echo "arguments wrong"; return 1; }
1652 while getopts "lt" option
1655 l
) arg_base
=$logdir ;;
1656 t
) do_stamp
=true
;;
1659 shift $
((OPTIND
- 1))
1661 [[ -e $logdir ]] || mkdir
-p $logdir
1662 $do_stamp && arg_base
+=$
(date +%F.
%T
%z
)
1663 script -t $arg_base.s
2> $arg_base.t
1665 splay
() { # script replay
1666 #logRoot="$HOME/typescripts/"
1667 #scriptreplay "$logRoot$1.t" "$logRoot$1.s"
1668 scriptreplay
"$1.t" "$1.s"
1672 # sudo redo. be aware, this command may not work right on strange distros or earlier software
1673 if [[ $# == 0 ]]; then
1674 sudo
-E bash
-c -l "$(history -p '!!')"
1676 echo this
command redos last
history item. no argument is accepted
1681 # with -ll, less secure but faster.
1682 command srm
-ll "$@"
1687 ssh $1 /tmp
/${2##*/} $
(printf "%q\n" "${@:2}")
1699 tclock
() { # terminal clock
1704 # this goes to full width
1705 #len=${1:-$((COLUMNS -7))}
1708 if (( x
== len
)); then
1710 d
="$(date +%l:%_M) "
1713 d
=$
(date +%l
:%M
:%_S
)
1717 for ((i
=0; i
<x
; i
++)); do
1718 if (( i
% 6 )); then
1736 # test existence / exists
1739 [[ -e "$x" ||
-L "$x" ]] || ret
=1
1745 # normally, i would just execute these commands in the function.
1746 # however, DEBUG is not inherited, so we need to run it outside a function.
1747 # And we want to run set -x afterwards to avoid spam, so we cram everything
1748 # in here, and then it will run after this function is done.
1749 PROMPT_COMMAND
='trap DEBUG; unset PROMPT_COMMAND; PS1="\w \$ "'
1752 PROMPT_COMMAND
=prompt-command
1753 if [[ $TERM == *(screen
*|xterm
*|rxvt
*) ]]; then
1754 trap 'settitle "$BASH_COMMAND"' DEBUG
1758 tx
() { # toggle set -x, and the prompt so it doesnt spam
1759 if [[ $
- == *x
* ]]; then
1768 # show all processes in the network namespace $1.
1769 # blank entries appear to be subprocesses/threads
1773 sudo
find -L /proc
/[1-9]*/task
/*/ns
/net
-samefile /run
/netns
/$netns | cut
-d/ -f5 | \
1775 x
=$
(ps
-w --no-headers -p $l);
1776 if [[ $x ]]; then echo "$x"; else echo $l; fi;
1780 m
() { printf "%s\n" "$*"; "$@"; }
1783 if type -p uprecords
&>/dev
/null
; then
1791 for x
in "$@"; do virsh destroy
"$x"; virsh undefine
"$x"; done
1799 sudo virsh dumpxml
$vm |
sed -r "s/(<listen.*address=')([^']+)/\1$ip/" | \
1800 sed -r "s/listen='[^']+/listen='$ip/"> $t
1801 sudo virsh undefine
$vm
1802 sudo virsh define
$t
1807 vm-set-listen
$1 0.0.0.0
1812 vm-set-listen
$1 127.0.0.1
1816 # find input, copy to pattern space, when we find the first field, print the copy in different order without newlines.
1817 # instead of using labels, we could just match a line and group, eg: /signal:/,{s/signal:(.*)/\1/h}
1818 sudo iw dev wls1 scan |
sed -rn "
1819 s/^\Wcapability: (.*)/\1/;Ta;h;b
1820 :a;s/^\Wsignal: -([^.]+).*/\1/;Tb;H;b
1821 # padded to min width of 20
1822 :b;s/\WSSID: (.*)/\1 /;T;s/^(.{20}(.*[^ ])?) */\1/;H;g;s/(.*)\n(.*)\n(.*)/\2 \3 \1/gp;b
1829 # temporary variables to test colorization
1830 # some copied from gentoo /etc/bash/bashrc,
1832 # dircolors --print-database uses its own built-in database
1833 # instead of using /etc/DIR_COLORS. Try to use the external file
1834 # first to take advantage of user additions.
1835 safe_term
=${TERM//[^[:alnum:]]/?} # sanitize TERM
1837 [[ -f ~
/.dir_colors
]] && match_lhs
="${match_lhs}$(<~/.dir_colors)"
1838 [[ -f /etc
/DIR_COLORS
]] && match_lhs
="${match_lhs}$(</etc/DIR_COLORS)"
1839 [[ -z ${match_lhs} ]] \
1840 && type -P dircolors
>/dev
/null \
1841 && match_lhs
=$
(dircolors
--print-database)
1842 # test if our $TERM is in the TERM values in dircolor
1843 [[ $
'\n'${match_lhs} == *$
'\n'"TERM "${safe_term}* ]] && use_color
=true
1846 if ${use_color} && [[ $
- == *i
* ]]; then
1848 term_bold
="$(tput bold)"
1849 term_red
="$(tput setaf 1)"
1850 term_green
="$(tput setaf 2)"
1851 term_yellow
="$(tput setaf 3)"
1852 term_purple
="$(tput setaf 5)"
1853 term_nocolor
="$(tput sgr0)" # no font attributes
1855 # unused so far. commented for shellcheck
1856 # term_underl="$(tput smul)"
1857 # term_blue="$(tput setaf 4)"
1858 # term_cyan="$(tput setaf 6)"
1861 # Try to keep environment pollution down, EPA loves us.
1862 unset safe_term match_lhs use_color
1867 if [[ $
- == *i
* ]]; then
1869 # this needs to come before next ps1 stuff
1870 # this stuff needs bash 4, feb 2009,
1871 # old enough to no longer condition on $BASH_VERSION anymore
1875 if [[ $
- == *i
* ]] && [[ ! $LC_INSIDE_EMACS ]]; then
1877 bind -m vi-command B
:shell-backward-word
1878 bind -m vi-command W
:shell-forward-word
1881 if [[ $SSH_CLIENT ||
$SUDO_USER ]]; then
1882 unset PROMPT_DIRTRIM
1886 # emacs terminal has problems if this runs slowly,
1887 # so I've thrown a bunch of things at the wall to speed it up.
1889 local return=$?
# this MUST COME FIRST
1890 local ps_char ps_color
1893 if [[ $HISTFILE ]]; then
1894 history -a # save history
1898 # shellcheck disable=SC1303
1899 if [[ $jr_pid ]]; then
1900 if [[ -e /proc
/$jr_pid ]]; then
1907 0) ps_color
="$term_purple"
1910 1) ps_color
="$term_green"
1911 ps_char
="$return \\$"
1913 *) ps_color
="$term_yellow"
1914 ps_char
="$return \\$"
1917 if [[ ! -O .
]]; then # not owner
1918 if [[ -w .
]]; then # writable
1919 ps_color
="$term_bold$term_red"
1921 ps_color
="$term_bold$term_green"
1925 # faster than sourceing the file im guessing
1926 if [[ -e /dev
/shm
/iank-status
&& ! -e /tmp
/quiet-status
]]; then
1927 eval $
(< /dev
/shm
/iank-status
)
1929 if [[ ! $SSH_CLIENT && $MAIL_HOST != "$HOSTNAME" ]]; then
1930 ps_char
="@ $ps_char"
1932 # We could test if sudo is active with sudo -nv
1933 # but then we get an email and log of lots of failed sudo commands.
1934 # We could turn those off, but seems better not to.
1935 if [[ $EUID != 0 ]] && [[ $DID_SUDO ]]; then
1936 ps_char
="SUDO $ps_char"
1938 PS1
="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$term_nocolor\] "
1940 # set titlebar. instead, using more advanced
1942 #echo -ne "$_title_escape $HOSTNAME ${PWD/#$HOME/~} \007"
1944 PROMPT_COMMAND
=prompt-command
1946 if [[ $TERM == screen
* ]]; then
1947 _title_escape
="\033]..2;"
1949 # somme sites recommend this, i dunno what the diff is.
1950 #_title_escape="\033]30;"
1951 _title_escape
="\033]0;"
1955 # this makes it so we show the current command if
1956 # one is running, otherwise, show nothing
1958 if [[ $1 == prompt-command
]]; then
1961 if (( ${#BASH_ARGC[@]} == 1 && BASH_SUBSHELL
== 0 )); then
1962 echo -ne "$_title_escape ${PWD/#$HOME/~} "
1968 # note, this wont work:
1969 # x=$(mktemp); cp a $x
1970 # I havnt figured out why, bigger fish to fry.
1973 # condition from the screen man page i think.
1974 # note: duplicated in tx()
1975 if [[ $TERM == *(screen
*|xterm
*|rxvt
*) ]]; then
1976 trap 'settitle "$BASH_COMMAND"' DEBUG
1983 # * stuff that makes sense to be at the end
1989 # shellcheck disable=SC1090
1990 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
1992 # I had this idea to start a bash shell which would run an initial
1993 # command passed through this env variable, then continue on
1994 # interactively. But the use case I had in mind went away.
1996 # if [[ $MY_INIT_CMD ]]; then
1997 # "${MY_INIT_CMD[@]}"
2001 # ensure no bad programs appending to this file will have an affect