2 # this gets sourced. shebang is just for file mode detection
4 # note, to catch errors in functions but not outside, do:
7 # trap 'trap ERR' RETURN
16 # remove all aliases. aliases provided by the system tend to get in the way,
17 # for example, error happens if I try to define a function the same name as an alias
20 # remove gnome keyring warning messages
21 # there is probably a more proper way, but I didnt find any easily on google
22 # now using xfce+xmonad instead of vanilla xmonad, so disabling this
23 #unset GNOME_KEYRING_CONTROL
25 # use extra globing features.
27 # include .files when globbing, but ignore files name . and ..
28 # setting this also sets dotglob.
29 # Note, this doesnt work in bash 4.4 anymore, for paths with
30 # more than 1 directory, like a/b/.foo, since * is fixed to not match /
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 # Also, enabling this before sourcing .bashrc makes PATH be empty.
41 # make tab on an empty line do nothing
42 shopt -s no_empty_cmd_completion
45 # http://bash-completion.alioth.debian.org/
46 # might be sourced by the system already, but ive noticed it not being sourced before
47 if ! type _init_completion
&> /dev
/null
&& [[ -r "/usr/share/bash-completion/bash_completion" ]]; then
48 .
/usr
/share
/bash-completion
/bash_completion
52 # fix spelling errors for cd, only in interactive shell
54 # append history instead of overwritting it
56 # for compatibility, per gentoo/debian bashrc
58 # attempt to save multiline single commands as single history entries.
65 if [[ $RLC_INSIDE_EMACS ]]; then
66 # EMACS is used by bash on startup, but we dont need it anymore.
67 # plus I hit a bug in a makefile which inherited it
69 export RLC_INSIDE_EMACS
72 # scp completion does not work, but this doesnt fix it. todo, figure this out
73 complete
-r scp
&> /dev
/null
74 # todo, remote file completion fails, figure out how to turn it off
75 export NODE_DISABLE_COLORS
=1
76 # This gets rid of ugly terminal escape chars in node repl
77 # sometime, Id like to have completion working in emacs shell for node
78 # the offending chars can be found in lib/readline.js,
79 # things that do like:
80 # stream.write('\x1b[' + (x + 1) + 'G');
81 # We can remove them and keep readline, for example by doing this
84 # var readline = require('readline');
85 # readline.cursorTo = function(a,b,c) {};
86 # readline.clearScreenDown = function(a) {};
87 # const repl = require('repl');
88 # var replServer = repl.start('');
90 # no prompt, or else readline complete seems to be confused, based
91 # on our column being different? node probably needs to send
92 # different kind of escape sequence that is not ugly. Anyways,
93 # completion doesnt work yet even with the ugly prompt, so whatever
95 export NODE_NO_READLINE
=1
100 if [[ $
- == *i
* ]]; then
101 # for readline-complete.el
102 if [[ $RLC_INSIDE_EMACS ]]; then
103 # all for readline-complete.el
105 bind 'set horizontal-scroll-mode on'
106 bind 'set print-completions-horizontally on'
107 bind '"\C-i": self-insert'
110 if [[ $KONSOLE_PROFILE_NAME ]]; then
114 # todo: not sure this works in sakura
116 #bind "\C-w": kill-region
117 # sakura == xterm-256color
119 if [[ $TERM == xterm
* ]]; then
120 # control + arrow keys. for other terminals, see http://unix.stackexchange.com/questions/10806/how-to-change-previous-next-word-shortcut-in-bash
121 bind '"\e[1;5C": shell-forward-word' 2>/dev
/null
122 bind '"\e[1;5D": shell-backward-word' 2>/dev
/null
124 # make ctrl-backspace work. for konsole, i fixed it through
125 # /home/iank/.local/share/konsole/default.keytab
127 bind '"\eOc": shell-forward-word'
128 bind '"\eOd": shell-backward-word'
130 # i cant remember why i did this, probably to free up some keys to bind
131 # to other things in bash.
132 # other than C-c and C-z, the rest defined by stty -a are, at least in
133 # gnome-terminal, overridden by bash, or disabled by the system
134 stty lnext undef stop undef start undef
140 # history number. History expansion is good.
142 # history file size limit, set to unlimited.
143 # this needs to be different from the default because
144 # default HISTFILESIZE is 500 and could clobber our history
146 # max commands 1 session can append/read from history
148 # my own history size limit based on lines
149 HISTFILELINES
=1000000
151 # the time format display when doing the history command
152 # also, setting this makes the history file record time
153 # of each command as seconds from the epoch
154 HISTTIMEFORMAT
="%Y-%m-%d %I:%M %p "
155 # consecutive duplicate lines dont go in history
156 HISTCONTROL
=ignoredups
157 # works in addition to HISTCONTROL to do more flexible things
158 # it could also do the same things as HISTCONTROL and thus replace it,
159 # but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
160 HISTIGNORE
='pass *:[ ]*:lom*:gram*'
162 export BC_LINE_LENGTH
=0
164 export PROFILE_TASKS_TASK_OUTPUT_LIMIT
=100
166 # note, if I use a machine I dont want files readable by all users, set
167 # 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
178 for _x
in /a
/bin
/distro-functions
/src
/* /a
/bin
/!(githtml
)/*-function?
(s
); do
182 # so I can share my bashrc
183 for x
in /a
/bin
/bash_unpublished
/source-
!(.
#*); do source $x; done
184 source $
(dirname $
(readlink
-f $BASH_SOURCE))/path_add-function
185 source /a
/bin
/log-quiet
/logq-function
186 # if someone exported $SOE (stop on error), catch errors.
188 # Note, on debian this results in the following warning when in ssh,
189 # hich I haven't figured out how to fix. It doesn't happen if we source
190 # after the shell has started
192 # bash: /usr/share/bashdb/bashdb-main.inc: No such file or directory
193 # bash: warning: cannot start debugger; debugging mode disabled
195 if [[ -e /a
/bin
/errhandle
/err
]]; then
196 source /a
/bin
/errhandle
/err
201 # add this with absolute paths as needed for better security
202 #path_add --end /path/to/node_modules/.bin
204 # pip3 --user things go here:
205 path_add
--end ~
/.local
/bin
206 path_add
--ifexists --end /a
/work
/libremanage
207 path_add
--ifexists --end /a
/opt
/adt-bundle
*/tools
/a
/opt
/adt-bundle
*/platform-tools
208 path_add
--ifexists --end /a
/opt
/scancode-toolkit-3.0
.2
210 # based on readme.debian. dunno if this will break on other distros.
211 _x
=/usr
/share
/wcd
/wcd-include.sh
212 if [[ -e $_x ]]; then source $_x; fi
217 # very few aliases, functions are always preferred.
220 if [[ $OS == Windows_NT
]]; then
221 alias ffs
='cygstart "/c/Program Files (x86)/Mozilla Firefox/firefox.exe" -P scratch'
223 alias j
='command cygpath'
224 alias t
='command cygstart'
225 alias cygstart
='echo be quick, use the alias "t" instead :\)'
226 alias cygpath
='echo be quick, use the alias "j" instead :\)'
231 # keep this in mind? good for safety.
236 # remove any default aliases for these
237 unalias ls ll
grep &>/dev
/null ||
:
246 ....
() { c ..
/..
/..
; }
247 .....
() { c ..
/..
/..
/..
; }
248 ......
() { c ..
/..
/..
/..
/..
; }
251 # file cut copy and paste, like the text buffers :)
252 # I havnt tested these.
253 _fbufferinit
() { # internal use by
254 ! [[ $my_f_tempdir ]] && my_f_tempdir
=$
(mktemp
-d)
255 rm -rf "$my_f_tempdir"/*
259 cp "$@" "$my_f_tempdir"/
263 mv "$@" "$my_f_tempdir"/
265 fpst
() { # file paste
266 [[ $2 ]] && { echo too many arguments
; return 1; }
268 cp "$my_f_tempdir"/* "$target"
273 complete
-F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr
277 # join options which are continued to multiples lines onto one line
279 grep -vE '^([ \t]*#|^[ \t]*$)' "$1" |
while IFS
= read -r line
; do
280 # remove leading spaces/tabs. assumes extglob
281 if [[ $line == "[ ]*" ]]; then
287 elif [[ $line == *=* ]]; then
288 echo "$pastline" >> "$2"
291 pastline
="$pastline $line"
294 echo "$pastline" >> "$2"
300 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")
302 echo "khfix: ssh failed"
305 if [[ $port != 22 ]]; then
306 ip_entry
="[$ip]:$port"
307 host_entry
="[$host]:$port"
312 ssh-keygen
-R "$host_entry" -f $
(readlink
-f ~
/.ssh
/known_hosts
)
313 echo "khfix: removing key for $ip_entry"
314 ssh-keygen
-R "$ip_entry" -f $
(readlink
-f ~
/.ssh
/known_hosts
)
316 khfix
() { # known hosts fix
317 _khfix_common
"$@" ||
return 1
326 local x
=$
(readlink
-nf "${1:-$PWD}")
327 # yes, its kinda dumb that xclip/xsel cant do this in one invocation
328 echo -n "$x" | xclip
-selection clipboard
332 ack
() { ack-grep
"$@"; }
335 if which anki
&>/dev
/null
; then
338 schroot
-c anki
-- anki
343 # pushd in case current directory has an ansible.cfg file
344 pushd /a
/xans
>/dev
/null
345 ansible-playbook
-v -l ${1:- $(hostname -f)} site.yml
349 pushd /a
/work
/ansible-configs
>/dev
/null
350 time ansible-playbook
-v -i inventory adhoc.yml
"$@"
354 pushd /a
/bin
/distro-setup
/a
>/dev
/null
355 ansible-playbook site.yml
360 # googling android emulator libGL error: failed to load driver: r600
361 # lead to http://stackoverflow.com/a/36625175/14456
362 export ANDROID_EMULATOR_USE_SYSTEM_LIBS
=1
363 /a
/opt
/android-studio
/bin
/studio.sh
"$@" &r
;
374 if systemctl is-active btrbk.service
; then
375 echo "cron btrbk is already running"
378 systemctl is-active btrbk.timer || active
=false
380 ser disable btrbk.timer
384 if ! btrbk-run
"$@" && $active; then
385 ser
enable btrbk.timer
389 bfg
() { java
-jar /a
/opt
/bfg-1.12
.14.jar
"$@"; }
392 xclock
-digital -update 1 -face 'arial black-80:bold'
400 switch-mail-host
$1 $HOSTNAME
407 switch-mail-host
$HOSTNAME $1
412 local f
=/etc
/bitcoin
/bitcoin.conf
413 # importprivkey will timeout if using the default of 15 mins.
414 # upped it to 1 hour.
415 bitcoin-cli
-rpcclienttimeout=60000 -$
(s
grep rpcuser
= $f) -$
(s
grep rpcpassword
= $f) "$@"
418 btcusd
() { # $1 btc in usd
420 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
421 printf "$%s\n" "$price"
423 printf "$%.2f\n" "$(echo "scale
=4; $price * $1"| bc -l)"
426 usdbtc
() { # $1 usd in btc
428 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
429 printf "$%s\n" "$price"
431 # 100 mil satoshi / btc. 8 digits after the 1.
432 printf "%.8f btc\n" "$(echo "scale
=10; $1 / $price "| bc -l)"
435 satoshi
() { # $1 satoshi in usd
437 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
438 price
=$
(echo "scale=10; $price * 0.00000001"|
bc -l)
439 printf "$%f\n" "$price"
441 printf "$%.2f\n" "$(echo "scale
=10; $price * $1"| bc -l)"
447 if [[ $RLC_INSIDE_EMACS ]]; then
448 c
() { wcd
-c -z 50 -o "$@"; }
450 # lets see what the fancy terminal does from time to time
451 c
() { wcd
-c -z 50 "$@"; }
454 caa
() { git commit
--amend --no-edit -a; }
457 find -L $1 -type f
-not \
( -name .svn
-prune -o -name .git
-prune \
458 -o -name .hg
-prune -o -name .editor-backups
-prune \
459 -o -name .undo-tree-history
-prune \
) \
460 -exec bash
-lc 'hr; echo "$1"; hr; cat "$1"' _
{} \
; 2>/dev
/null
464 calc
() { echo "scale=3; $*" |
bc -l; }
465 # no having to type quotes, but also no command history:
469 echo "scale=3; $x" |
bc -l
476 cbfstool
() { /a
/opt
/coreboot
/build
/cbfstool
"$@"; }
478 ccat
() { # config cat. see a config without extra lines.
479 grep '^\s*[^;[:space:]#]' "$@"
484 # setup for format of postfix, eg:
488 local unified
="$(mktemp)"
491 _cdiff-prep
"$1" "$f1"
492 _cdiff-prep
"$2" "$f2"
493 cat "$f1" "$f2" |
grep -Po '^[^=]+=' |
sort |
uniq > "$unified"
494 while IFS
= read -r line
; do
495 # the default bright red / blue doesnt work in emacs shell
496 dwdiff
-cblue,red
-A best
-d " ," <(grep "^$line" "$f1" ||
echo ) <(grep "^$line" "$f2" ||
echo ) | colordiff
503 cp /a
/bin
/data
/COPYING
"$@"
505 cp /a
/bin
/data
/COPYING .
512 cp /a
/bin
/data
/LICENSE
"$@"
514 cp /a
/bin
/data
/LICENSE .
521 inotifywait
-m "$dir" -e create
-e moved_to |
522 while read filedir _
file; do
525 calc $
((SECONDS
- start
)) / 60
532 # makes it so chown -R symlink affects the symlink and its target.
533 if [[ $1 == -R ]]; then
535 command chown
-h "$@"
536 command chown
-R "$@"
547 # choose recent directory. cl = cd list
552 if type -p chromium
&>/dev
/null
; then
556 cmd
="schroot -c stretch chromium"
557 CHROMIUM_FLAGS
='--enable-remote-extensions' $cmd &r
562 complete
-A stopped
-P '"%' -S '"' d
564 dat
() { # do all tee, for more complex scripts
565 tee >(ssh frodo bash
-l) >(bash
-l) >(ssh x2 bash
-l) >(ssh tp bash
-l)
570 for host in x2 tp kd
; do
576 diff --strip-trailing-cr -w "$@" # diff content
579 debian_pick_mirror
() {
580 # netselect-apt finds a fast mirror.
581 # but we need to replace the mirrors ourselves,
582 # because it doesnt do that. best it can do is
583 # output a basic sources file
584 # here we get the server it found, get the main server we use
585 # then substitute all instances of one for the other in the sources file
586 # and backup original to /etc/apt/sources.list-original.
587 # this is idempotent. the only way to identify debian sources is to
588 # note the original server, so we put it in a comment so we can
590 local file=$
(mktemp
-d)/f
# safe way to get file name without creating one
591 sudo netselect-apt
-o "$file" ||
return 1
592 url
=$
(grep ^
\\w
$file |
head -n1 |
awk '{print $2}')
593 sudo
cp -f /etc
/apt
/sources.list
/etc
/apt
/sources.list-original
594 sudo
sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc
/apt
/sources.list
602 safe_rename
"$x" "$y"
607 date "+%A, %B %d, %r" "$@"
610 dus
() { # du, sorted, default arg of
611 du
-sh ${@:-*} |
sort -h
620 [[ ${#@} == 2 ]] ||
{ echo "error: ediff requires 2 arguments"; return 1; }
621 emacs
--eval "(ediff-files \"$1\" \"$2\")"
625 envload
() { # load environment from a previous: export > file
626 local file=${1:-$HOME/.${USER}_env}
627 eval "$(export | sed 's/^declare -x/export -n/')"
628 while IFS
= read -r line
; do
629 # declare -x makes variables local to a function
630 eval ${line/#declare -x/export}
636 sudo
tail -F /var
/log
/exim
4/mainlog
-n 50
645 # find array. make an array of file names found by find into $x
646 # argument: find arguments
647 # return: find results in an array $x
648 while read -rd ''; do
650 done < <(find "$@" -print0);
653 faf
() { # find all files
654 find -L $1 -not \
( -name .svn
-prune -o -name .git
-prune \
655 -o -name .hg
-prune -o -name .editor-backups
-prune \
656 -o -name .undo-tree-history
-prune \
) -type f
2>/dev
/null
659 # one that comes with distros is too old for newer devices
661 /a
/opt
/android-platform-tools
/fastboot
"$@";
664 kdecd
() { /usr
/lib
/x86_64-linux-gnu
/libexec
/kdeconnectd
; }
666 # List of apps to install/update
667 # Create from existing manually installed apps by doing
669 # fdroidcl search -i, then manually removing
670 # automatically installed/preinstalled apps
673 # # my attempt at recovering from boot loop:
674 # # in that case, boot to recovery (volume up, home button, power, let go of power after samsun logo)
676 # mount /dev/block/mmcblk0p12 /data
678 # find -iname '*appname*'
680 # usually good enough to just rm -rf /data/app/APPNAME
683 # # causes replicant to crash
684 # org.quantumbadger.redreader
685 # org.kde.kdeconnect_tp
687 # not broke, but wont work without gps
688 #com.zoffcc.applications.zanavi
689 # not broke, but not using atm
690 #com.nutomic.syncthingandroid
691 # # doesn\'t work on replicant
692 #net.sourceforge.opencamera
695 de.marmaro.krt.ffupdater
696 me.ccrama.redditslide
697 org.fedorahosted.freeotp
699 com.alaskalinuxuser.justnotes
700 com.artifex.mupdf.viewer.app
701 com.danielkim.soundrecorder
703 com.ghostsq.commander
705 com.jmstudios.redmoon
707 org.kde.kdeconnect_tp
710 cz.martykan.forecastie
713 de.marmaro.krt.ffupdater
714 eu.siacs.conversations
716 im.vector.alpha
# riot
718 me.tripsit.tripmobile
720 net.minetest.minetest
725 org.smssecure.smssecure
727 sh.
ftp.rocketninelabs.meditationassistant.opensource
729 # https://forum.xda-developers.com/android/software-hacking/wip-selinux-capable-superuser-t3216394
734 local -A installed updated
737 if fdroidcl search
-u |
grep ^org.fdroid.fdroid
; then
738 fdroidcl
install org.fdroid.fdroid
742 for p
in $
(fdroidcl search
-i|
grep -o "^\S\+"); do
745 for p
in $
(fdroidcl search
-u|
grep -o "^\S\+"); do
748 for p
in ${fdroid_pkgs[@]}; do
749 if ! ${installed[$p]:-false}; then
751 # sleeps are just me being paranoid since replicant has a history of crashing when certain apps are installed
755 for p
in ${!installed[@]}; do
756 if ! ${updated[$p]:-true}; then
763 firefox-default-profile
() {
764 key
=Default value
=1 section
=$1
765 file=/p
/c
/subdir_files
/.mozilla
/firefox
/profiles.ini
766 sed -ri "/^ *$key/d" "$file"
767 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d};/ *\[$section\]/a $key=$value" "$file"
769 fdhome
() { #firefox default home profile
770 firefox-default-profile Profile0
774 firefox-default-profile Profile4
778 if type -P firefox
&>/dev
/null
; then
788 firefox
-P alt
"$@" >/dev
/null
2>&1
794 local dname
="${PWD##*/}"
795 local m
="/a/tmp/$dname-missing"
796 local d
="/a/tmp/$dname-diff"
797 [[ -e $d ]] && rm "$d"
798 [[ -e $m ]] && rm "$m"
801 while read -r line
; do
803 if [[ -e "$fsfile" ]]; then
804 md5diff
"$line" "$fsfile" && tee -a "/a/tmp/$dname-diff" <<< "$fsfile $line"
810 done < <(find -type f
)
813 (( msize
<= 100 )) && cat $m
817 # expected output, with different tmp dirs
818 # /tmp/tmp.HDPbwMqdC9/c/d ./c/d
819 # /a/tmp/tmp.qLDkYxBYPM-missing
828 echo different
> $x/c
/d
833 # test whether missing files were renamed, generally for use with fsdiff
834 # $1 = fsdiff output file, $2 = directory to compare to. pwd = fsdiff dir
835 # echos non-renamed files
839 { sums
+=( "$(md5sum < "$x")" ) ; } 2>/dev
/null
841 while read -r line
; do
842 { missing_sum
=$
(md5sum < "$line") ; } 2>/dev
/null
844 for x
in "${sums[@]}"; do
845 if [[ $missing_sum == "$x" ]]; then
850 $renamed ||
echo "$line"
856 # F = fullscren, z = random, Z = auto zoom
857 command feh
-FzZ "$@"
863 s mailq |gr frozen|
awk '{print $3}' |
while read -r id
; do
869 echo -e '\n\n##############################\n'
870 done |
tee -a /tmp
/frozen
874 while read -r line
; do
875 printf '%s\n' "$line"
876 ids
+=($
(printf '%s\n' "$line" |gr frozen|
awk '{print $3}'))
878 echo "sleeping for 2 in case you change your mind"
880 s exim
-Mrm "${ids[@]}"
884 # like -e for functions. returns on error.
885 # at the end of the function, disable with:
887 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
888 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"
895 firefox
-P default
"$@" >/dev
/null
2>&1
899 local help="Usage: getdir [--help] PATH
900 Output the directory of PATH, or just PATH if it is a directory."
901 if [[ $1 == --help ]]; then
905 if [[ $# -ne 1 ]]; then
906 echo "getdir error: expected 1 argument, got $#"
912 local dir
="$(dirname "$1")"
913 if [[ -d $dir ]]; then
916 echo "getdir error: directory does not exist"
922 git_empty_branch
() { # start an empty git branch. carefull, it deletes untracked files.
923 [[ $# == 1 ]] ||
{ echo 'need a branch name!'; return 1;}
925 gitroot ||
return 1 # function to set gitroot
926 builtin cd "$gitroot"
927 git symbolic-ref HEAD refs
/heads
/$1
933 local help="Usage: gitroot [--help]
934 Print the full path to the root of the current git repo
936 Handles being within a .git directory, unlike git rev-parse --show-toplevel,
937 and works in older versions of git which did not have that."
938 if [[ $1 == --help ]]; then
942 local p
=$
(git rev-parse
--git-dir) ||
{ echo "error: not in a git repo" ; return 1; }
943 [[ $p != /* ]] && p
=$PWD
948 git config user.email ian@iankelling.org
952 # i got an error, gh not found when doing a pull request, it seems like it wants itself in it\'s path.
953 local _oldpath
="$PATH"
954 PATH
="$PATH:~/node_modules/.bin"
960 # quit will prompt if the program crashes.
961 gdb
-ex=r
-ex=quit
--args emacs
"$@"; r
;
965 # kill the emacs daemon
969 # at least in flidas, things rely on gpg being gpg1
975 local email
=ian@iankelling.org
976 if readlink ~
/.mu |
grep fsf
&>/dev
/null
; then
979 git send-email
--notes "--envelope-sender=<$email>" \
980 --suppress-cc=self
"$@"
984 grep -iIP --color=auto
"$@"
987 grr
() { # grep recursive
988 if [[ ${#@} == 1 ]]; then
989 grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto
"$@" .
991 grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto
"$@"
995 command rg
-i -M 200 "$@"
999 # do git status on published repos
1003 cd `readlink -f $x`/..
1004 status
=$
(i status
-s) ||
pwd
1005 if [[ $status ]]; then
1008 printf "%s\n" "$status"
1014 hl
() { # history limit. Write extra history to archive file.
1015 # todo: this is not working or not used currently
1016 local max_lines linecount tempfile prune_lines x
1017 local harchive
="${HISTFILE}_archive"
1018 for x
in "$HISTFILE" "$harchive"; do
1019 [[ -e $x ]] ||
{ touch "$x" && echo "notice from hl(): creating $x"; }
1020 if [[ ! $x ||
! -e $x ||
! -w $x || $
(stat
-c "%u" "$x") != $EUID ]]; then
1021 echo "error in hl: history file \$x:$x no good"
1025 history -a # save history
1026 max_lines
=$HISTFILELINES
1027 [[ $max_lines =~ ^
[0-9]+$
]] ||
{ echo "error in hl: failed to get max line count"; return 1; }
1028 linecount
=$
(wc -l < $HISTFILE) # pipe so it doesnt output a filename
1029 [[ $linecount =~ ^
[0-9]+$
]] ||
{ echo "error in hl: wc failed"; return 1; }
1030 if (($linecount > $max_lines)); then
1031 prune_lines
=$
(($linecount - $max_lines))
1032 head -n $prune_lines "$HISTFILE" >> "$harchive" \
1033 && sed --follow-symlinks -ie "1,${prune_lines}d" $HISTFILE
1037 hr
() { # horizontal row. used to break up output
1038 printf "$(tput setaf 5)â–ˆ$(tput sgr0)%.0s" $
(seq ${COLUMNS:-60})
1042 hrcat
() { local f
; for f
; do [[ -f $f ]] ||
continue; hr
; echo "$f"; cat "$f"; done }
1044 # get latest hub and run it
1045 # main command to use:
1046 # hub pull-request --no-edit
1047 # --no-edit means to use the first commit\'s message as the pull request message.
1048 # Also, you need to use a feature branch, not master in your fork.
1049 # On first use, you input username/pass and it gets an oath token so you dont have to repeat
1050 # it\'s at ~/.config/hub
1052 local up uptar updir p
1053 p
=/github
/hub
/releases
/
1054 up
=https
://github.com
/$
(curl
-s https
://github.com
$p|
grep -o $p'download/[^/]*/hub-linux-amd64[^"]*' |
head -n1)
1057 if [[ ! -e /a
/opt
/$updir ]]; then
1058 rm -rf /a
/opt
/hub-linux-amd64
*
1060 tar -C /a
/opt
-zxf /a
/opt
/$uptar
1062 s
/a
/opt
/$updir/install
1065 # save token across computers
1066 if [[ ! -L ~
/.config
/hub
]]; then
1067 if [[ -e ~
/.config
/hub
]]; then
1068 mv ~
/.config
/hub
/p
/c
/subdir_files
/.config
/
1070 if [[ -e /p
/c
/subdir_files
/.config
/hub
]]; then
1078 # modified from ~/local/bin/git-completion.bash
1079 # other completion commands are mostly taken from bash_completion package
1080 complete
-o bashdefault
-o default
-o nospace
-F _git i
2>/dev
/null \
1081 || complete
-o default
-o nospace
-F _git i
1083 if ! type service
&>/dev
/null
; then
1085 echo actually running
: systemctl
$2 $1
1097 /a
/opt
/idea-IC-163.7743
.44/bin
/idea.sh
"$@" &r
1102 find -L .
-not \
( -name .svn
-prune -o -name .git
-prune \
1103 -o -name .hg
-prune -o -name .editor-backups
-prune \
1104 -o -name .undo-tree-history
-prune \
) -iname "*$**" 2>/dev
/null
1109 if type gvfs-open
&> /dev
/null
; then
1114 # another alternative is run-mailcap
1118 s iptables
-A INPUT
-s $1 -j DROP
1123 grep -Il "" "$@" &>/dev
/null
1127 grep -Evi -e "^(\S+\s+){4}(sudo|sshd|cron)\[\S*:" \
1128 -e "^(\S+\s+){4}systemd\[\S*: (starting|started) (btrfsmaintstop|dynamicipupdate|spamd dns bug fix cronjob|rss2email)\.*$"
1131 journalctl
-n 10000 -f "$@" | jfilter
1133 jr
() { journalctl
"$@" | jfilter |
less ; }
1134 jrf
() { journalctl
-f "$@" | jfilter
; }
1136 kff
() { # keyboardio firmware flash
1137 pushd /a
/bin
/distro-setup
/Arduino
/Model01-Firmware
1138 yes $
'\n' |
make flash
1143 if [[ $PWD == /[iap
] ]]; then
1144 command ls -A --color=auto
-I lost
+found
"$@"
1146 command ls -A --color=auto
"$@"
1151 lcn
() { locate -i "*$**"; }
1153 lg
() { LC_COLLATE
=C.UTF-8 ll
--group-directories-first; }
1155 lt
() { ll
-tr "$@"; }
1157 lld
() { ll
-d "$@"; }
1161 if [[ $1 == /* ]]; then
1163 if mountpoint
/mnt
/$base; then
1166 l
=$
(sudo losetup
-f)
1168 if ! sudo cryptsetup luksOpen
$l $base; then
1172 sudo mkdir
-p /mnt
/$base
1173 sudo mount
/dev
/mapper
/$base /mnt
/$base
1174 sudo chown
$USER:$USER /mnt
/$base
1177 sudo umount
/mnt
/$base
1178 l
=$
(sudo cryptsetup status
/dev
/mapper
/$base|
sed -rn 's/^\s*device:\s*(.*)/\1/p')
1179 sudo cryptsetup luksClose
/dev
/mapper
/$base ||
return 1
1184 low
() { # make filenames lowercase, remove bad chars
1187 new
="${f,,}" # downcase
1188 new
="${new//[^[:alnum:]._-]/_}" # sub bad chars
1189 new
="${new#"${new%%[[:alnum:]]*}"}" # remove leading/trailing non-alnum
1190 new
="${new%"${new##*[[:alnum:]]}"}"
1191 # remove bad underscores, like __ and _._
1192 new
=$
(echo $new |
sed -r 's/__+/_/g;s/_+([.-])|([.-])_+/\1/g')
1193 safe_rename
"$f" "$new" ||
return 1
1198 lower
() { # make first letter of filenames lowercase.
1201 if [[ ${x::1} == [A-Z
] ]]; then
1202 y
=$
(tr "[A-Z]" "[a-z]" <<<"${x::1}")"${x:1}"
1203 safe_rename
"$x" "$y" ||
return 1
1209 k
() { # history search
1210 grep -P --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
tail -n 80;
1213 ks
() { # history search
1214 grep -P --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
uniq;
1219 # show make targets, via http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make
1220 make -qp |
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
1228 [[ -e $src ]] ||
{ set +x
; return 1; }
1229 mv -T $src $dst ||
{ set +x
; return 1; }
1232 mu index
--maildir=/m
/4e
1240 [[ -e $src ]] ||
{ set +x
; return 1; }
1241 if [[ -L $dst ]]; then rm $dst; fi
1248 markdown
"$1" >/tmp
/mdtest.html
1249 firefox
/tmp
/mdtest.html
1262 mkt
() { # mkdir and touch file
1264 mkdir
-p "$(dirname "$path")"
1268 mkdir
() { command mkdir
-p "$@"; }
1270 mo
() { xset dpms force off
; } # monitor off
1273 e
"lspci -nnk|gr -iA2 net"
1274 lspci
-nnk|gr
-iA2 net
1276 e
"s lshw -C network"
1283 ser stop NetworkManager
1285 s resolvconf
-d NetworkManager
1291 ser start NetworkManager
1297 sudo
tee -a /var
/log
/exim
4/paniclog-archive
</var
/log
/exim
4/paniclog
; sudo truncate
-s0 /var
/log
/exim
4/paniclog
1302 oathtool
--totp -b "$@" | xclip
-selection clipboard
1305 p8
() { ping 8.8.8.8; }
1308 # from http://askubuntu.com/questions/456021/remove-vocals-from-mp3-and-get-only-instrumentals
1309 pactl load-module module-ladspa-sink sink_name
=Karaoke master
=alsa_output.usb-Audioengine_Audioengine_D1-00.analog-stereo plugin
=karaoke_1409 label
=karaoke control
=-30
1313 pfind
() { #find *$1* in $PATH
1314 [[ $# != 1 ]] && { echo requires
1 argument
; return 1; }
1316 IFS
=: pathArray
=($PATH); unset IFS
1317 find "${pathArray[@]}" -iname "*$1*"
1320 pkx
() { # package extract
1323 cached
=$
(ls -t /var
/cache
/apt
/archives
/$pkg* |
tail -n1)
1324 if [[ $cached ]]; then
1327 aptitude download
$pkg
1336 pid
=($
(pgrep
-f "$*"))
1342 0) echo "no pid found" ;;
1350 # trash-restore lists everything that has been trashed at or below CWD
1351 # This picks out files just in CWD, not subdirectories,
1352 # which also match grep $1, usually use $1 for a time string
1353 # which you get from running restore-trash once first
1356 # last condition is to not ask again for ones we skipped
1357 while name
="$( echo | restore-trash | gr "$PWD/[^
/]\
+$
" | gr "$1" )" \
1358 && [[ $name ]] && (( $
(wc -l <<<"$name") >= nth
)); do
1359 name
="$(echo "$name" | head -n $nth | tail -n 1 )"
1360 read -p "$name [Y/n] " ask
1361 if [[ ! $ask ||
$ask == [Yy
] ]]; then
1362 x
=$
( echo "$name" | gr
-o "^\s*[0-9]*" )
1363 echo $x | restore-trash
> /dev
/null
1364 elif [[ $ask == [Nn
] ]]; then
1374 rld
/a
/h
/_site
/ li
:/var
/www
/iankelling.org
/html
1377 pubip
() { curl
-4s https
://icanhazip.com
; }
1378 pubip6
() { curl
-6s https
://icanhazip.com
; }
1379 whatismyip
() { pubip
; }
1382 # fixes the menu bar in xmonad. this won\'t be needed when xmonad
1383 # packages catches up on some changes in future (this is written in
1386 # geekosaur: so youll want to upgrade to xmonad 0.13 or else use a
1387 # locally modified XMonad.Hooks.ManageDocks that doesnt set the
1388 # work area; turns out it\'s impossible to set correctly if you are
1389 # not a fully EWMH compliant desktop environment
1391 # geekosaur: chrome shows one failure mode, qt/kde another, other
1392 # gtk apps a third, ... I came up with a setting that works for me
1393 # locally but apparently doesnt work for others, so we joined the
1394 # other tiling window managers in giving up on setting it at all
1396 xprop
-root -remove _NET_WORKAREA
1404 # -t = print pronunciation
1406 for (( i
=0; i
<10; i
++ )); do
1407 shuf
-n3 /usr
/share
/hunspell
/en_US.dic |
sed 's,/.*,,' |
paste -sd .
-
1413 # -M CLN = use Caps, Lowercase, Numbers
1415 # -a 1 = use random instead of pronounceable algorithm
1416 apg
-m 50 -x 70 -n 1 -a 1 -M CLN
1420 q
() { # start / launch a program in the backround and redir output to null
1425 exit "$@" 2>/dev
/null
1428 rbpipe
() { rbt post
-o --diff-filename=- "$@"; }
1429 rbp
() { rbt post
-o "$@"; }
1440 hr
; echo dnsmasq is $
(systemctl is-active dnsmasq
)
1441 f
=/var
/run
/dnsmasq
/resolv.conf
1442 hr
; echo $f:; ccat
$f
1443 f
=/etc
/dnsmasq-servers.conf
1444 hr
; echo $f:; ccat
$f
1448 # rsync, root is required to keep permissions right.
1449 # rsync --archive --human-readable --verbose --itemize-changes --checksum \(-ahvic\) \
1450 # --no-times --delete
1451 # basically, make an exact copy, use checksums instead of file times to be more accurate
1452 rsync
-ahvic --delete "$@"
1455 # like rlu, but dont delete files on the target end which
1456 # do not exist on the original end.
1459 complete
-F _rsync
-o nospace rld rl rlt
1462 # rl without preserving modification time.
1463 rsync
-ahvic --delete --no-t "$@"
1466 rlu
() { # [OPTS] HOST PATH
1467 # eg. rlu -opts frodo /testpath
1468 # relative paths will expanded with readlink -f.
1469 # useful for selectively sending dirs which have been synced with unison,
1470 # where the path is the same on both hosts.
1471 opts
=("${@:1:$#-2}") # 1 to last -2
1472 path
="${@:$#}" # last
1473 host="${@:$#-1:1}" # last -1
1474 if [[ $path == .
* ]]; then
1475 path
=$
(readlink
-f $path)
1477 # rync here uses checksum instead of time so we dont mess with
1478 # unison relying on time as much. g is for group, same reason
1479 # to keep up with unison.
1480 s rsync
-rlpchviog --relative "${opts[@]}" "$path" "root@$host:/";
1483 # only run on MAIL_HOST. simpler to keep this on one system.
1484 r2eadd
() { # usage: name url
1485 # initial setup of rss2email:
1486 # r2e new r2e@iankelling.org
1487 # that initializes files, and sets default email.
1488 # symlink to the config doesnt work, so I copied it to /p/c
1489 # and then use cli option to specify explicit path.
1490 # Only option changed from default config is to set
1493 # or else for a few feeds, the from address is set by the feed, and
1494 # if I fail delivery, then I send a bounce message to that from
1495 # address, which makes me be a spammer.
1497 r2e add
$1 "$2" $1@r2e.iankelling.org
1498 # get up to date and dont send old entries now:
1499 r2e run
--no-send $1
1501 r2e
() { command r2e
-d /p
/c
/rss2email.json
-c /p
/c
/rss2email.cfg
"$@"; }
1503 rspicy
() { # usage: HOST DOMAIN
1504 # connect to spice vm remote host. use vspicy for local host
1505 local port
=$
(ssh $1<<EOF
1506 sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
1507 sed -rn "s/.*port='([0-9]+).*/\1/p"
1510 if [[ $port ]]; then
1511 spicy
-h $1 -p $port
1513 echo "error: no port found. check that the domain is running."
1518 ssh fencepost
head -n 300 /gd
/gnuorg
/EventAndTravelInfo
/rms-current-trips.txt |
less
1523 # I use a function because otherwise we cant use in a script,
1524 # cant assign to variable.
1526 # note: gksudo is recommended for X apps because it does not set the
1527 # home directory to the same, and thus apps writing to ~ fuck things up
1528 # with root owned files.
1530 if [[ $EUID != 0 ||
$1 == -* ]]; then
1531 SUDOD
="$PWD" sudo
-i "$@"
1537 safe_rename
() { # warn and dont rename if file exists.
1538 # mv -n exists, but it\'s silent
1539 if [[ $# != 2 ]]; then
1540 echo safe_rename error
: $# args
, need
2 >2
1543 if [[ $1 != $2 ]]; then # yes, we want to silently ignore this
1544 if [[ -e $2 ||
-L $2 ]]; then
1545 echo "Cannot rename $1 to $2 as it already exists."
1553 sb
() { # sudo bash -c
1554 # use sb instead of s is for sudo redirections,
1555 # eg. sb 'echo "ok fine" > /etc/file'
1557 sudo
-i bash
-c "$@"
1559 complete
-F _root_command s sb
1562 # s gem install scss-lint
1563 pushd /a
/opt
/thoughtbot-guides
1566 scss-lint
-c /a
/opt
/thoughtbot-guides
/style
/sass
/.scss-lint.yml
"$@"
1570 local s
; [[ $EUID != 0 ]] && s
=s
1571 if type -p systemctl
&>/dev
/null
; then
1577 # like restart, but do nothing if its not already started
1580 if [[ $
(s systemctl
--no-pager show
-p ActiveState
$service ) == ActiveState
=active
]]; then
1581 systemctl restart
$service
1585 setini
() { # set a value in a .ini style file
1586 key
="$1" value
="$2" section
="$3" file="$4"
1587 if [[ -s $file ]]; then
1588 sed -ri -f - "$file" <<EOF
1589 # remove existing keys
1590 / *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d}
1592 /^\s*\[$section\]/a $key=$value
1593 # from section to eof, do nothing
1594 /^\s*\[$section\]/,\$b
1595 # on the last line, if we haven't found section yet, add section and key
1607 sgo
() { # service go
1609 ser restart
$service ||
return 1
1610 if type -p systemctl
&>/dev
/null
; then
1617 # 2086 = unquoted $var
1618 # 2046 = unquoted $(cmd)
1619 # i had -x as an arg, but debian testing(stretch) doesn\'t support it
1620 shellcheck
-e 2086,2046,2068,2006,2119 "$@"
1626 out
=${2:-${1%.*}.sh}
1628 script -t -c "mpv --no-config --no-resume-playback --no-terminal --no-audio-display '$1'" $tmp/typescript
2>$tmp/timing
1629 # todo, the current sleep seems pretty good, but it
1630 # would be nice to have an empirical measurement, or
1631 # some better wait to sync up.
1633 # note: --loop-file=no prevents it from hanging if you have that
1634 # set to inf the mpv config.
1635 # --loop=no prevents it from exit code 3 due to stdin if you
1636 # had it set to inf in mpv config.
1638 # args go to mpv, for example --volume=80, 50%
1639 cat >$out <<EOFOUTER
1641 trap "trap - TERM && kill 0" INT TERM ERR; set -e
1642 ( sleep .2; scriptreplay <( cat <<'EOF'
1646 $(cat $tmp/typescript)
1649 base64 -d - <<'EOF'| mpv --loop=no --loop-file=no --no-terminal --no-audio-display "\$@" -
1659 # log with script. timing is $1.t and script is $1.s
1660 # -l to save to ~/typescripts/
1661 # -t to add a timestamp to the filenames
1662 local logdir do_stamp arg_base
1663 (( $# >= 1 )) ||
{ echo "arguments wrong"; return 1; }
1666 while getopts "lt" option
1669 l
) arg_base
=$logdir ;;
1670 t
) do_stamp
=true
;;
1673 shift $
(($OPTIND - 1))
1675 [[ -e $logdir ]] || mkdir
-p $logdir
1676 $do_stamp && arg_base
+=$
(date +%F.
%T
%z
)
1677 script -t $arg_base.s
2> $arg_base.t
1679 splay
() { # script replay
1680 #logRoot="$HOME/typescripts/"
1681 #scriptreplay "$logRoot$1.t" "$logRoot$1.s"
1682 scriptreplay
"$1.t" "$1.s"
1685 smeld
() { # ssh meld usage host1 host2 file
1686 meld
<(ssh $1 cat $3) <(ssh $2 cat $3)
1690 PATH
=/usr
/local
/spdhackfix
:$PATH command spd
"$@"
1698 # sudo redo. be aware, this command may not work right on strange distros or earlier software
1699 if [[ $# == 0 ]]; then
1700 sudo
-E bash
-c -l "$(history -p '!!')"
1702 echo this
command redos last
history item. no argument is accepted
1707 # with -ll, less secure but faster.
1708 command srm
-ll "$@"
1713 ssh $1 /tmp
/${2##*/} "${@:2}"
1717 ssh -oControlMaster=no
-oControlPath=/ "$@"
1721 while [[ $1 == -* ]]; do
1725 m pkill
-f "^ssh: /tmp/ssh_mux_${USER}_${1#*@}_22_"
1726 m
ssh "${opts[@]}" "$@"
1740 if type -t trash-put
>/dev
/null
; then
1741 # skip args that dont exist, or else trash-put will have an error
1743 if [[ -e $x ||
-L $x ]]; then
1747 [[ ! ${args[@]} ]] || trash-put
"${args[@]}"
1758 # this goes to full width
1759 #len=${1:-$((COLUMNS -7))}
1762 if (( x
== len
)); then
1764 d
="$(date +%l:%_M) "
1767 d
=$
(date +%l
:%M
:%_S
)
1771 for ((i
=0; i
<x
; i
++)); do
1772 if (( i
% 6 )); then
1790 # test existence / exists
1793 [[ -e "$x" ||
-L "$x" ]] || ret
=1
1800 declare -gi _seq
; _seq
+=1
1801 echo "test body" | m
mail -s "test mail from $HOSTNAME, $_seq" "${@:-root@localhost}"
1802 # for testing to send from an external address, you can do for example
1803 # -fian@iank.bid -aFrom:ian@iank.bid web-6fnbs@mail-tester.com
1804 # note in exim, you can retry a deferred message
1806 # MSG_ID is in /var/log/exim4/mainlog, looks like 1ccdnD-0001nh-EN
1809 # to test sieve, use below command. for fsf mail, see fsf-get-mail script.
1810 # make modifications, then copy to live file, use -eW to actually modify mailbox
1811 # cp /p/c/subdir_files/sieve/personal{test,}.sieve; testsievelist -eW INBOX
1813 # Another option is to use sieve-test SCRIPT MAIL_FILE. note,
1814 # sieve-test doesnt know about envelopes, Im not sure if sieve-filter does.
1816 # sieve with output filter. arg is mailbox, like INBOX.
1817 # This depends on dovecot conf, notably mail_location in /etc/dovecot/conf.d/10-mail.conf
1820 sieve-filter ~
/sieve
/maintest.sieve
"$@" >/tmp
/testsieve.log
2> >(tail) && sed -rn '/^Performed actions:/{n;n;p}' /tmp
/testsieve.log |
sort -u
1827 sieve-filter ~
/sieve
/main.sieve
"$@"
1832 # testmail above calls sendmail, which is a link to exim/postfix.
1833 # its docs dont say a way of adding an argument
1834 # to sendmail to turn on debug output. We could make a wrapper, but
1835 # that is a pain. Exim debug args are documented here:
1836 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
1838 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-building_and_installing_exim.html
1839 # note, for exim daemon, you can turn on debug options by
1840 # adding -d, etc to COMMONOPTIONS in
1841 # /etc/default/exim4
1843 From: ian@iankelling.org
1844 To: root@lists0p.fsf.org
1845 Subject: Testing Exim
1847 This is a test message.
1854 # https://askubuntu.com/questions/160945/is-there-a-way-to-disable-a-laptops-internal-keyboard
1855 id
=$
(xinput
--list --id-only 'AT Translated Set 2 keyboard')
1856 if xinput list |
grep -F '∼ AT Translated Set 2 keyboard' &>/dev
/null
; then
1857 echo enabling keyboard
1858 # find the first slave keyboard number, they are all the same in my output.
1859 # if they werent, worst case we would need to save the slave number somewhere
1860 # when it got disabled.
1861 slave
=$
(xinput list |
sed -n 's/.*slave \+keyboard (\([0-9]*\)).*/\1/p' |
head -n1)
1862 xinput reattach
$id $slave
1871 (sleep $
(calc
"$@ * 60") && mpv
--no-config --volume 50 /a
/bin
/data
/alarm.mp3
) > /dev
/null
2>&1 &
1874 trg
() { transmission-remote-gtk
&r
; }
1876 # example, set global upload limit to 100 kilobytes:
1878 TR_AUTH
=":$(jq -r .profiles[0].password ~/.config/transmission-remote-gtk/config.json)" transmission-remote transmission.lan
-ne "$@"
1884 local dir
="$(dirname "$1")"
1885 if [[ -e $1 && ! -w $1 ||
! -w $
(dirname "$1") ]]; then
1891 tx
() { # toggle set -x, and the prompt so it doesnt spam
1892 if [[ $
- == *x
* ]]; then
1894 PROMPT_COMMAND
=prompt-command
1895 # disabled due to issue on stretch, running ll we get error. something
1896 # about the DEBUG trap is broken
1897 # if [[ $TERM == *(screen*|xterm*|rxvt*) ]]; then
1898 # trap 'settitle "$BASH_COMMAND"' DEBUG
1901 # normally, i would just execute these commands in the function.
1902 # however, DEBUG is not inherited, so we need to run it outside a function.
1903 # And we want to run set -x afterwards to avoid spam, so we cram everything
1904 # in here, and then it will run after this function is done.
1905 #PROMPT_COMMAND='trap DEBUG; unset PROMPT_COMMAND; PS1="\w \$ "; set -x'
1907 unset PROMPT_COMMAND
1914 # show all processes in the network namespace $1.
1915 # blank entries appear to be subprocesses/threads
1919 s
find -L /proc
/[1-9]*/task
/*/ns
/net
-samefile /run
/netns
/$netns | cut
-d/ -f5 | \
1921 x
=$
(ps
-w --no-headers -p $l);
1922 if [[ $x ]]; then echo "$x"; else echo $l; fi;
1926 m
() { printf "%s\n" "$*"; "$@"; }
1930 #m s nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*pia.conf") -n -m "$@"
1931 m s nsenter
-t $
(pgrep
-f "/usr/sbin/openvpn .* --config /etc/openvpn/.*client.conf") -n -m "$@"
1934 vpncmd gksudo
-u iank
"firefox -no-remote -P vpn" &r
1937 vpncmd gksudo
-u iank
"$*"
1946 for x
in "$@"; do virsh destroy
"$x"; virsh undefine
"$x"; done
1953 s virsh dumpxml
$vm |
sed -r "s/(<listen.*address=')([^']+)/\1$ip/" | \
1954 sed -r "s/listen='[^']+/listen='$ip/"> $t
1955 s virsh undefine
$vm
1961 vm-set-listen
$1 0.0.0.0
1966 vm-set-listen
$1 127.0.0.1
1971 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
1972 local vpn_service
=openvpn-client
1974 local vpn_service
=openvpn
1977 [[ $1 ]] ||
{ echo need arg
; return 1; }
1978 journalctl
--unit=$vpn_service@
$1 -f -n0 &
1979 s systemctl start
$vpn_service@
$1
1980 # sometimes the ask-password agent does not work and needs a delay.
1982 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779240
1983 # noticed around 8-2017 after update from around stretch release
1984 # on debian testing, even though the bug is much older.
1985 s systemd-tty-ask-password-agent
1989 [[ $1 ]] ||
{ echo need arg
; return 1; }
1990 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
1991 local vpn_service
=openvpn-client
1993 local vpn_service
=openvpn
1995 s systemctl stop
$vpn_service@
$1
2006 vspicy
() { # usage: VIRSH_DOMAIN
2007 # connect to vms made with virt-install
2008 spicy
-p $
(sudo virsh dumpxml
"$1"|
grep "<graphics.*type='spice'"|\
2009 sed -r "s/.*port='([0-9]+).*/\1/")
2013 cat-new-files
/m
/4e
/INBOX
/new
2016 wtr
() { curl wttr.in
/boston
; }
2018 xevkb
() { xev
-event keyboard
; }
2022 # from curl cheat.sh/:bash_completion
2023 _cheatsh_complete_curl
()
2026 _get_comp_words_by_ref
-n : cur
2029 #cur="${COMP_WORDS[COMP_CWORD]}"
2030 prev
="${COMP_WORDS[COMP_CWORD-1]}"
2031 opts
="$(curl -s cheat.sh/:list | sed s@^@cheat.sh/@)"
2033 if [[ ${cur} == cheat.sh
/* ]] ; then
2034 COMPREPLY
=( $
(compgen
-W "${opts}" -- ${cur}) )
2035 __ltrim_colon_completions
"$cur"
2039 complete
-F _cheatsh_complete_curl curl
2042 if [[ $
- == *i
* ]]; then
2043 # commands to run when bash exits normally
2048 # temporary variables to test colorization
2049 # some copied from gentoo /etc/bash/bashrc,
2051 # dircolors --print-database uses its own built-in database
2052 # instead of using /etc/DIR_COLORS. Try to use the external file
2053 # first to take advantage of user additions.
2054 safe_term
=${TERM//[^[:alnum:]]/?} # sanitize TERM
2056 [[ -f ~
/.dir_colors
]] && match_lhs
="${match_lhs}$(<~/.dir_colors)"
2057 [[ -f /etc
/DIR_COLORS
]] && match_lhs
="${match_lhs}$(</etc/DIR_COLORS)"
2058 [[ -z ${match_lhs} ]] \
2059 && type -P dircolors
>/dev
/null \
2060 && match_lhs
=$
(dircolors
--print-database)
2061 # test if our $TERM is in the TERM values in dircolor
2062 [[ $
'\n'${match_lhs} == *$
'\n'"TERM "${safe_term}* ]] && use_color
=true
2065 if ${use_color} && [[ $
- == *i
* ]]; then
2067 if [[ $XTERM_VERSION == Cygwin
* ]]; then
2071 underl
) echo -n $
'\E[4m' ;;
2072 bold
) echo -n $
'\E[1m' ;;
2073 red
) echo -n $
'\E[31m' ;;
2074 green
) echo -n $
'\E[32m' ;;
2075 blue
) echo -n $
'\E[34m' ;;
2076 cyan
) echo -n $
'\E[36m' ;;
2077 yellow
) echo -n $
'\E[33m' ;;
2078 purple
) echo -n $
'\E[35m' ;;
2079 nocolor
) echo -n $
'\E(B\E[m' ;;
2088 underl
) echo -n $
(tput smul
) ;;
2089 bold
) echo -n $
(tput bold
) ;;
2090 red
) echo -n $
(tput setaf
1) ;;
2091 green
) echo -n $
(tput setaf
2) ;;
2092 blue
) echo -n $
(tput setaf
4) ;;
2093 cyan
) echo -n $
(tput setaf
6) ;;
2094 yellow
) echo -n $
(tput setaf
3) ;;
2095 purple
) echo -n $
(tput setaf
5) ;;
2096 nocolor
) echo -n $
(tput sgr0
) ;; # no font attributes
2106 # Try to keep environment pollution down, EPA loves us.
2107 unset safe_term match_lhs use_color
2114 if [[ $
- == *i
* ]]; then
2115 # git branch/status prompt function
2116 if [[ $OS != Windows_NT
]]; then
2117 GIT_PS1_SHOWDIRTYSTATE
=true
2119 # arch source lopip show -fcation
2120 [[ -r /usr
/share
/git
/git-prompt.sh
]] && source /usr
/share
/git
/git-prompt.sh
2121 # fedora/debian source
2122 [[ -r /usr
/share
/git-core
/contrib
/completion
/git-prompt.sh
]] && source /usr
/share
/git-core
/contrib
/completion
/git-prompt.sh
2124 # in case we didnt source git-prompt.sh
2125 if ! declare -f __git_ps1
> /dev
/null
; then
2131 # this needs to come before next ps1 stuff
2132 # this stuff needs bash 4, feb 2009,
2133 # old enough to no longer condition on $BASH_VERSION anymore
2137 if [[ $
- == *i
* ]] && [[ ! $RLC_INSIDE_EMACS ]]; then
2139 bind -m vi-command B
:shell-backward-word
2140 bind -m vi-command W
:shell-forward-word
2143 if [[ $SSH_CLIENT ||
$SUDO_USER ]]; then
2148 local return=$?
# this MUST COME FIRST
2149 local psc pst ps_char ps_color stale_subvol
2151 history -a # save history
2156 0) ps_color
="$(get_term_color blue)"
2159 1) ps_color
="$(get_term_color green)"
2160 ps_char
="$return \\$"
2162 *) ps_color
="$(get_term_color yellow)"
2163 ps_char
="$return \\$"
2166 if [[ ! -O .
]]; then # not owner
2167 if [[ -w .
]]; then # writable
2168 ps_color
="$(get_term_color bold red)"
2170 ps_color
="$(get_term_color bold green)"
2173 # I would set nullglob, but bash has had bugs where that
2174 # doesnt work if not in top level.
2175 if [[ -e /nocow
/btrfs-stale
]] && ((`command ls -AUq /nocow/btrfs-stale|wc -l`)); then
2176 ps_char
="! $ps_char"
2178 if [[ ! $SSH_CLIENT && $MAIL_HOST != $HOSTNAME ]]; then
2179 ps_char
="@ $ps_char"
2181 PS1
="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
2182 # emacs completion doesnt like the git prompt atm, so disabling it.
2183 #PS1="${PS1%"${PS1#*[wW]}"}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
2185 PROMPT_COMMAND
=prompt-command
2188 if [[ $TERM == screen
* ]]; then
2189 local title_escape
="\033]..2;"
2191 local title_escape
="\033]0;"
2193 if [[ $
* != prompt-command
]]; then
2194 echo -ne "$title_escape$USER@$HOSTNAME ${PWD/#$HOME/~} "
2201 # condition from the screen man page i think.
2202 # note: duplicated in tx()
2203 # disabled. see note in tx
2204 # if [[ $TERM == *(screen*|xterm*|rxvt*) ]]; then
2205 # trap 'settitle "$BASH_COMMAND"' DEBUG
2213 # we also have a file in /a/c/...konsole...
2214 local f
=$HOME/.config
/konsolerc
2215 setini DefaultProfile profileian.profile
"Desktop Entry" $f
2216 setini Favorites profileian.profile
"Favorite Profiles" $f
2217 setini ShowMenuBarByDefault false KonsoleWindow
$f
2218 setini TabBarPosition Top TabBar
$f
2223 setini
$k $v sakura
/a
/c
/subdir_files
/.config
/sakura
/sakura.conf
2225 colorset1_back rgb(33,37,39
2229 disable_numbered_tabswitch true
2230 scroll_lines 10000000
2235 reset-xscreensaver
() {
2236 # except for spash, i set these by setting gui options in
2237 # xscreensaver-command -demo
2238 # then finding the corresponding option in .xscreensaver
2239 # spash, i happened to notice in .xscreensaver
2241 # dpmsOff, monitor doesnt come back on using old free software supported nvidia card
2242 cat > /home
/iank
/.xscreensaver
<<'EOF'
2245 dpmsStandby: 0:02:00
2246 dpmsSuspend: 0:03:00
2250 lockTimeout: 0:03:00
2257 # * stuff that makes sense to be at the end
2258 if [[ "$SUDOD" ]]; then
2261 elif [[ -d /a
]] && [[ $PWD == $HOME ]] && [[ $
- == *i
* ]]; then
2270 # for mitmproxy to get a newer python.
2271 # commented until i want to use it because it
2272 # noticably slows bash startup
2276 if [[ $EUID == 0 ||
! -e ~
/.pyenv
/bin
]]; then
2277 echo "error: dont be root. make sure pyenv is installed"
2280 export PATH
="~/.pyenv/bin:$PATH"
2281 eval "$(pyenv init -)"
2282 eval "$(pyenv virtualenv-init -)"
2286 export GOPATH
=$HOME/go
2287 path_add
$GOPATH/bin
2288 path_add
/usr
/local
/go
/bin
2290 # I have the git repo and a release. either one should work.
2291 # I have both because I was trying to solve an issue that
2292 # turned out to be unrelated.
2293 # ARDUINO_PATH=/a/opt/Arduino/build/linux/work
2294 export ARDUINO_PATH
=/a
/opt
/arduino-1.8
.9
2296 # They want to be added to the start, but i think
2297 # that should be avoided unless we really need it.
2298 path_add
--end ~
/.npm-global
2300 path_add
--end $HOME/.cargo
/bin
2302 # taken from default changes to bashrc and bash_profile
2303 path_add
--end $HOME/.rvm
/bin
2304 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
2306 export BASEFILE_DIR
=/a
/bin
/fai-basefiles
2308 export ANDROID_HOME
=/opt
/android
2310 # didnt get drush working, if I did, this seems like the
2311 # only good thing to include for it.
2312 # Include Drush completion.
2313 # if [ -f "/home/ian/.drush/drush.complete.sh" ] ; then
2314 # source /home/ian/.drush/drush.complete.sh
2318 # https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
2319 # i added an extra condition as gentoo xorg guide says depending on
2320 # $DISPLAY is fragile.
2321 if [[ ! $DISPLAY && $XDG_VTNR == 1 ]] && shopt -q login_shell
&& isarch
; then
2326 # ensure no bad programs appending to this file will have an affect