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
99 # emacs has a different default search path than the info command. This
100 # adds the info defaults to emacs, but not the reverse, because I dun
101 # care much about the cli. The search path is only on the cli if you run
102 # "info xxx", or in emacs if you run '(info xxx)', so not that
103 # important, but might as well fix it.
105 # info info says this path is what was compiled, and its not documented
106 # anywhere. Through source grepping, i found it in filesys.h of the info
107 # source in trisquel flidas.
109 # Traling : means for emacs to add its own stuff on to the end.
111 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
:.
:
113 if [[ $
- == *i
* ]]; then
114 # for readline-complete.el
115 if [[ $RLC_INSIDE_EMACS ]]; then
116 # all for readline-complete.el
118 bind 'set horizontal-scroll-mode on'
119 bind 'set print-completions-horizontally on'
120 bind '"\C-i": self-insert'
123 if [[ $KONSOLE_PROFILE_NAME ]]; then
127 # todo: not sure this works in sakura
129 #bind "\C-w": kill-region
130 # sakura == xterm-256color
132 if [[ $TERM == xterm
* ]]; then
133 # control + arrow keys. for other terminals, see http://unix.stackexchange.com/questions/10806/how-to-change-previous-next-word-shortcut-in-bash
134 bind '"\e[1;5C": shell-forward-word' 2>/dev
/null
135 bind '"\e[1;5D": shell-backward-word' 2>/dev
/null
137 # make ctrl-backspace work. for konsole, i fixed it through
138 # /home/iank/.local/share/konsole/default.keytab
140 bind '"\eOc": shell-forward-word'
141 bind '"\eOd": shell-backward-word'
143 # i cant remember why i did this, probably to free up some keys to bind
144 # to other things in bash.
145 # other than C-c and C-z, the rest defined by stty -a are, at least in
146 # gnome-terminal, overridden by bash, or disabled by the system
147 stty lnext undef stop undef start undef
153 # history number. History expansion is good.
155 # history file size limit, set to unlimited.
156 # this needs to be different from the default because
157 # default HISTFILESIZE is 500 and could clobber our history
159 # max commands 1 session can append/read from history
161 # my own history size limit based on lines
162 HISTFILELINES
=1000000
164 # the time format display when doing the history command
165 # also, setting this makes the history file record time
166 # of each command as seconds from the epoch
167 HISTTIMEFORMAT
="%Y-%m-%d %I:%M %p "
168 # consecutive duplicate lines dont go in history
169 HISTCONTROL
=ignoredups
170 # works in addition to HISTCONTROL to do more flexible things
171 # it could also do the same things as HISTCONTROL and thus replace it,
172 # but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
173 HISTIGNORE
='pass *:[ ]*:otp *:oathtool *'
175 export BC_LINE_LENGTH
=0
177 export PROFILE_TASKS_TASK_OUTPUT_LIMIT
=100
179 # note, if I use a machine I dont want files readable by all users, set
180 # umask 077 # If fewer than 4 digits are entered, leading zeros are assumed
184 # i for insensitive. the rest from
185 # X means dont remove the current screenworth of output upon exit
186 # R means to show colors n things
188 export SYSTEMD_LESS
=$LESS
191 for _x
in /a
/bin
/distro-functions
/src
/* /a
/bin
/!(githtml
)/*-function?
(s
); do
195 # so I can share my bashrc
196 for x
in /a
/bin
/bash_unpublished
/source-
!(.
#*); do source $x; done
197 source $
(dirname $
(readlink
-f $BASH_SOURCE))/path_add-function
198 source /a
/bin
/log-quiet
/logq-function
199 # if someone exported $SOE (stop on error), catch errors.
201 # Note, on debian this results in the following warning when in ssh,
202 # hich I haven't figured out how to fix. It doesn't happen if we source
203 # after the shell has started
205 # bash: /usr/share/bashdb/bashdb-main.inc: No such file or directory
206 # bash: warning: cannot start debugger; debugging mode disabled
208 if [[ -e /a
/bin
/errhandle
/err
]]; then
209 source /a
/bin
/errhandle
/err
214 # add this with absolute paths as needed for better security
215 #path_add --end /path/to/node_modules/.bin
217 # pip3 --user things go here:
218 path_add
--end ~
/.local
/bin
219 path_add
--ifexists --end /a
/work
/libremanage
220 path_add
--ifexists --end /a
/opt
/adt-bundle
*/tools
/a
/opt
/adt-bundle
*/platform-tools
221 path_add
--ifexists --end /a
/opt
/scancode-toolkit-3.0
.2
223 # based on readme.debian. dunno if this will break on other distros.
224 _x
=/usr
/share
/wcd
/wcd-include.sh
225 if [[ -e $_x ]]; then source $_x; fi
230 # very few aliases, functions are always preferred.
233 if [[ $OS == Windows_NT
]]; then
234 alias ffs
='cygstart "/c/Program Files (x86)/Mozilla Firefox/firefox.exe" -P scratch'
236 alias j
='command cygpath'
237 alias t
='command cygstart'
238 alias cygstart
='echo be quick, use the alias "t" instead :\)'
239 alias cygpath
='echo be quick, use the alias "j" instead :\)'
244 # keep this in mind? good for safety.
249 # remove any default aliases for these
250 unalias ls ll
grep &>/dev
/null ||
:
259 ....
() { c ..
/..
/..
; }
260 .....
() { c ..
/..
/..
/..
; }
261 ......
() { c ..
/..
/..
/..
/..
; }
264 # file cut copy and paste, like the text buffers :)
265 # I havnt tested these.
266 _fbufferinit
() { # internal use by
267 ! [[ $my_f_tempdir ]] && my_f_tempdir
=$
(mktemp
-d)
268 rm -rf "$my_f_tempdir"/*
272 cp "$@" "$my_f_tempdir"/
276 mv "$@" "$my_f_tempdir"/
278 fpst
() { # file paste
279 [[ $2 ]] && { echo too many arguments
; return 1; }
281 cp "$my_f_tempdir"/* "$target"
286 complete
-F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr
290 # join options which are continued to multiples lines onto one line
292 grep -vE '^([ \t]*#|^[ \t]*$)' "$1" |
while IFS
= read -r line
; do
293 # remove leading spaces/tabs. assumes extglob
294 if [[ $line == "[ ]*" ]]; then
300 elif [[ $line == *=* ]]; then
301 echo "$pastline" >> "$2"
304 pastline
="$pastline $line"
307 echo "$pastline" >> "$2"
313 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")
315 echo "khfix: ssh failed"
318 if [[ $port != 22 ]]; then
319 ip_entry
="[$ip]:$port"
320 host_entry
="[$host]:$port"
325 ssh-keygen
-R "$host_entry" -f $
(readlink
-f ~
/.ssh
/known_hosts
)
326 echo "khfix: removing key for $ip_entry"
327 ssh-keygen
-R "$ip_entry" -f $
(readlink
-f ~
/.ssh
/known_hosts
)
329 khfix
() { # known hosts fix
330 _khfix_common
"$@" ||
return 1
339 local x
=$
(readlink
-nf "${1:-$PWD}")
340 # yes, its kinda dumb that xclip/xsel cant do this in one invocation
341 echo -n "$x" | xclip
-selection clipboard
345 ack
() { ack-grep
"$@"; }
348 if which anki
&>/dev
/null
; then
351 schroot
-c anki
-- anki
356 # pushd in case current directory has an ansible.cfg file
357 pushd /a
/xans
>/dev
/null
358 ansible-playbook
-v -l ${1:- $(hostname -f)} site.yml
362 pushd /a
/work
/ansible-configs
>/dev
/null
363 time ansible-playbook
-v -i inventory adhoc.yml
"$@"
367 pushd /a
/bin
/distro-setup
/a
>/dev
/null
368 ansible-playbook site.yml
373 # googling android emulator libGL error: failed to load driver: r600
374 # lead to http://stackoverflow.com/a/36625175/14456
375 export ANDROID_EMULATOR_USE_SYSTEM_LIBS
=1
376 /a
/opt
/android-studio
/bin
/studio.sh
"$@" &r
;
387 systemctl is-active btrbk.timer || active
=false
389 ser disable btrbk.timer
391 if systemctl is-active btrbk.service
; then
392 $active && ser
enable btrbk.timer
393 echo "cron btrbk is already running"
399 $active && ser
enable btrbk.timer
402 bfg
() { java
-jar /a
/opt
/bfg-1.12
.14.jar
"$@"; }
405 xclock
-digital -update 1 -face 'arial black-80:bold'
413 switch-mail-host
$1 $HOSTNAME
420 switch-mail-host
$HOSTNAME $1
425 local f
=/etc
/bitcoin
/bitcoin.conf
426 # importprivkey will timeout if using the default of 15 mins.
427 # upped it to 1 hour.
428 bitcoin-cli
-rpcclienttimeout=60000 -$
(s
grep rpcuser
= $f) -$
(s
grep rpcpassword
= $f) "$@"
431 btcusd
() { # $1 btc in usd
433 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
434 printf "$%s\n" "$price"
436 printf "$%.2f\n" "$(echo "scale
=4; $price * $1"| bc -l)"
439 usdbtc
() { # $1 usd in btc
441 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
442 printf "$%s\n" "$price"
444 # 100 mil satoshi / btc. 8 digits after the 1.
445 printf "%.8f btc\n" "$(echo "scale
=10; $1 / $price "| bc -l)"
448 satoshi
() { # $1 satoshi in usd
450 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
451 price
=$
(echo "scale=10; $price * 0.00000001"|
bc -l)
452 printf "$%f\n" "$price"
454 printf "$%.2f\n" "$(echo "scale
=10; $price * $1"| bc -l)"
460 if [[ $RLC_INSIDE_EMACS ]]; then
461 c
() { wcd
-c -z 50 -o "$@"; }
463 # lets see what the fancy terminal does from time to time
464 c
() { wcd
-c -z 50 "$@"; }
467 caa
() { git commit
--amend --no-edit -a; }
470 find -L $1 -type f
-not \
( -name .svn
-prune -o -name .git
-prune \
471 -o -name .hg
-prune -o -name .editor-backups
-prune \
472 -o -name .undo-tree-history
-prune \
) \
473 -exec bash
-lc 'hr; echo "$1"; hr; cat "$1"' _
{} \
; 2>/dev
/null
477 calc
() { echo "scale=3; $*" |
bc -l; }
478 # no having to type quotes, but also no command history:
482 echo "scale=3; $x" |
bc -l
489 cbfstool
() { /a
/opt
/coreboot
/build
/cbfstool
"$@"; }
491 ccat
() { # config cat. see a config without extra lines.
492 grep '^\s*[^;[:space:]#]' "$@"
497 # setup for format of postfix, eg:
501 local unified
="$(mktemp)"
504 _cdiff-prep
"$1" "$f1"
505 _cdiff-prep
"$2" "$f2"
506 cat "$f1" "$f2" |
grep -Po '^[^=]+=' |
sort |
uniq > "$unified"
507 while IFS
= read -r line
; do
508 # the default bright red / blue doesnt work in emacs shell
509 dwdiff
-cblue,red
-A best
-d " ," <(grep "^$line" "$f1" ||
echo ) <(grep "^$line" "$f2" ||
echo ) | colordiff
516 cp /a
/bin
/data
/COPYING
"$@"
518 cp /a
/bin
/data
/COPYING .
525 cp /a
/bin
/data
/LICENSE
"$@"
527 cp /a
/bin
/data
/LICENSE .
534 inotifywait
-m "$dir" -e create
-e moved_to |
535 while read filedir _
file; do
538 calc $
((SECONDS
- start
)) / 60
545 # makes it so chown -R symlink affects the symlink and its target.
546 if [[ $1 == -R ]]; then
548 command chown
-h "$@"
549 command chown
-R "$@"
560 # choose recent directory. cl = cd list
565 if type -p chromium
&>/dev
/null
; then
569 cmd
="schroot -c stretch chromium"
570 CHROMIUM_FLAGS
='--enable-remote-extensions' $cmd &r
575 complete
-A stopped
-P '"%' -S '"' d
577 dat
() { # do all tee, for more complex scripts
578 tee >(ssh frodo bash
-l) >(bash
-l) >(ssh x2 bash
-l) >(ssh tp bash
-l)
583 for host in x2 tp kd
; do
589 diff --strip-trailing-cr -w "$@" # diff content
592 debian_pick_mirror
() {
593 # netselect-apt finds a fast mirror.
594 # but we need to replace the mirrors ourselves,
595 # because it doesnt do that. best it can do is
596 # output a basic sources file
597 # here we get the server it found, get the main server we use
598 # then substitute all instances of one for the other in the sources file
599 # and backup original to /etc/apt/sources.list-original.
600 # this is idempotent. the only way to identify debian sources is to
601 # note the original server, so we put it in a comment so we can
603 local file=$
(mktemp
-d)/f
# safe way to get file name without creating one
604 sudo netselect-apt
-o "$file" ||
return 1
605 url
=$
(grep ^
\\w
$file |
head -n1 |
awk '{print $2}')
606 sudo
cp -f /etc
/apt
/sources.list
/etc
/apt
/sources.list-original
607 sudo
sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc
/apt
/sources.list
615 safe_rename
"$x" "$y"
620 date "+%A, %B %d, %r" "$@"
623 dus
() { # du, sorted, default arg of
624 du
-sh ${@:-*} |
sort -h
631 # echo var. print var including escapes, etc
633 printf "%qEOL\n" "${!1}"
634 printf "%s" "${!1}" |
& hexdump -C
639 [[ ${#@} == 2 ]] ||
{ echo "error: ediff requires 2 arguments"; return 1; }
640 emacs
--eval "(ediff-files \"$1\" \"$2\")"
644 envload
() { # load environment from a previous: export > file
645 local file=${1:-$HOME/.${USER}_env}
646 eval "$(export | sed 's/^declare -x/export -n/')"
647 while IFS
= read -r line
; do
648 # declare -x makes variables local to a function
649 eval ${line/#declare -x/export}
655 sudo
tail -F /var
/log
/exim
4/mainlog
-n 50
664 # find array. make an array of file names found by find into $x
665 # argument: find arguments
666 # return: find results in an array $x
667 while read -rd ''; do
669 done < <(find "$@" -print0);
672 faf
() { # find all files
673 find -L $1 -not \
( -name .svn
-prune -o -name .git
-prune \
674 -o -name .hg
-prune -o -name .editor-backups
-prune \
675 -o -name .undo-tree-history
-prune \
) -type f
2>/dev
/null
678 # one that comes with distros is too old for newer devices
680 /a
/opt
/android-platform-tools
/fastboot
"$@";
683 kdecd
() { /usr
/lib
/x86_64-linux-gnu
/libexec
/kdeconnectd
; }
685 # List of apps to install/update
686 # Create from existing manually installed apps by doing
688 # fdroidcl search -i, then manually removing
689 # automatically installed/preinstalled apps
692 # # my attempt at recovering from boot loop:
693 # # in that case, boot to recovery (volume up, home button, power, let go of power after samsun logo)
695 # mount /dev/block/mmcblk0p12 /data
697 # find -iname '*appname*'
699 # usually good enough to just rm -rf /data/app/APPNAME
702 # # causes replicant to crash
703 # org.quantumbadger.redreader
704 # org.kde.kdeconnect_tp
706 # not broke, but wont work without gps
707 #com.zoffcc.applications.zanavi
708 # not broke, but not using atm
709 #com.nutomic.syncthingandroid
710 # # doesn\'t work on replicant
711 #net.sourceforge.opencamera
714 de.marmaro.krt.ffupdater
715 me.ccrama.redditslide
716 org.fedorahosted.freeotp
718 com.alaskalinuxuser.justnotes
719 com.artifex.mupdf.viewer.app
720 com.danielkim.soundrecorder
722 com.ghostsq.commander
724 com.jmstudios.redmoon
726 org.kde.kdeconnect_tp
729 cz.martykan.forecastie
732 de.marmaro.krt.ffupdater
733 eu.siacs.conversations
735 im.vector.alpha
# riot
737 me.tripsit.tripmobile
739 net.minetest.minetest
744 org.smssecure.smssecure
746 sh.
ftp.rocketninelabs.meditationassistant.opensource
748 # https://forum.xda-developers.com/android/software-hacking/wip-selinux-capable-superuser-t3216394
753 local -A installed updated
756 if fdroidcl search
-u |
grep ^org.fdroid.fdroid
; then
757 fdroidcl
install org.fdroid.fdroid
761 for p
in $
(fdroidcl search
-i|
grep -o "^\S\+"); do
764 for p
in $
(fdroidcl search
-u|
grep -o "^\S\+"); do
767 for p
in ${fdroid_pkgs[@]}; do
768 if ! ${installed[$p]:-false}; then
770 # sleeps are just me being paranoid since replicant has a history of crashing when certain apps are installed
774 for p
in ${!installed[@]}; do
775 if ! ${updated[$p]:-true}; then
782 firefox-default-profile
() {
783 key
=Default value
=1 section
=$1
784 file=/p
/c
/subdir_files
/.mozilla
/firefox
/profiles.ini
785 sed -ri "/^ *$key/d" "$file"
786 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d};/ *\[$section\]/a $key=$value" "$file"
788 fdhome
() { #firefox default home profile
789 firefox-default-profile Profile0
793 firefox-default-profile Profile4
797 if type -P firefox
&>/dev
/null
; then
807 firefox
-P alt
"$@" >/dev
/null
2>&1
813 local dname
="${PWD##*/}"
814 local m
="/a/tmp/$dname-missing"
815 local d
="/a/tmp/$dname-diff"
816 [[ -e $d ]] && rm "$d"
817 [[ -e $m ]] && rm "$m"
820 while read -r line
; do
822 if [[ -e "$fsfile" ]]; then
823 md5diff
"$line" "$fsfile" && tee -a "/a/tmp/$dname-diff" <<< "$fsfile $line"
829 done < <(find -type f
)
832 (( msize
<= 100 )) && cat $m
836 # expected output, with different tmp dirs
837 # /tmp/tmp.HDPbwMqdC9/c/d ./c/d
838 # /a/tmp/tmp.qLDkYxBYPM-missing
847 echo different
> $x/c
/d
852 # test whether missing files were renamed, generally for use with fsdiff
853 # $1 = fsdiff output file, $2 = directory to compare to. pwd = fsdiff dir
854 # echos non-renamed files
858 { sums
+=( "$(md5sum < "$x")" ) ; } 2>/dev
/null
860 while read -r line
; do
861 { missing_sum
=$
(md5sum < "$line") ; } 2>/dev
/null
863 for x
in "${sums[@]}"; do
864 if [[ $missing_sum == "$x" ]]; then
869 $renamed ||
echo "$line"
875 # F = fullscren, z = random, Z = auto zoom
876 command feh
-FzZ "$@"
882 s mailq |gr frozen|
awk '{print $3}' |
while read -r id
; do
888 echo -e '\n\n##############################\n'
889 done |
tee -a /tmp
/frozen
893 while read -r line
; do
894 printf '%s\n' "$line"
895 ids
+=($
(printf '%s\n' "$line" |gr frozen|
awk '{print $3}'))
897 echo "sleeping for 2 in case you change your mind"
899 s exim
-Mrm "${ids[@]}"
903 # like -e for functions. returns on error.
904 # at the end of the function, disable with:
906 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
907 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"
914 firefox
-P default
"$@" >/dev
/null
2>&1
918 local help="Usage: getdir [--help] PATH
919 Output the directory of PATH, or just PATH if it is a directory."
920 if [[ $1 == --help ]]; then
924 if [[ $# -ne 1 ]]; then
925 echo "getdir error: expected 1 argument, got $#"
931 local dir
="$(dirname "$1")"
932 if [[ -d $dir ]]; then
935 echo "getdir error: directory does not exist"
941 git_empty_branch
() { # start an empty git branch. carefull, it deletes untracked files.
942 [[ $# == 1 ]] ||
{ echo 'need a branch name!'; return 1;}
944 gitroot ||
return 1 # function to set gitroot
945 builtin cd "$gitroot"
946 git symbolic-ref HEAD refs
/heads
/$1
952 local help="Usage: gitroot [--help]
953 Print the full path to the root of the current git repo
955 Handles being within a .git directory, unlike git rev-parse --show-toplevel,
956 and works in older versions of git which did not have that."
957 if [[ $1 == --help ]]; then
961 local p
=$
(git rev-parse
--git-dir) ||
{ echo "error: not in a git repo" ; return 1; }
962 [[ $p != /* ]] && p
=$PWD
967 git config user.email ian@iankelling.org
971 # i got an error, gh not found when doing a pull request, it seems like it wants itself in it\'s path.
972 local _oldpath
="$PATH"
973 PATH
="$PATH:~/node_modules/.bin"
979 # quit will prompt if the program crashes.
980 gdb
-ex=r
-ex=quit
--args emacs
"$@"; r
;
984 # kill the emacs daemon
988 # at least in flidas, things rely on gpg being gpg1
994 local email
=ian@iankelling.org
995 if readlink ~
/.mu |
grep fsf
&>/dev
/null
; then
998 git send-email
--notes "--envelope-sender=<$email>" \
999 --suppress-cc=self
"$@"
1003 grep -iIP --color=auto
"$@"
1006 grr
() { # grep recursive
1007 if [[ ${#@} == 1 ]]; then
1008 grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto
"$@" .
1010 grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto
"$@"
1014 command rg
-i -M 200 "$@"
1018 # do git status on published repos
1022 cd `readlink -f $x`/..
1023 status
=$
(i status
-s) ||
pwd
1024 if [[ $status ]]; then
1027 printf "%s\n" "$status"
1033 hl
() { # history limit. Write extra history to archive file.
1034 # todo: this is not working or not used currently
1035 local max_lines linecount tempfile prune_lines x
1036 local harchive
="${HISTFILE}_archive"
1037 for x
in "$HISTFILE" "$harchive"; do
1038 [[ -e $x ]] ||
{ touch "$x" && echo "notice from hl(): creating $x"; }
1039 if [[ ! $x ||
! -e $x ||
! -w $x || $
(stat
-c "%u" "$x") != $EUID ]]; then
1040 echo "error in hl: history file \$x:$x no good"
1044 history -a # save history
1045 max_lines
=$HISTFILELINES
1046 [[ $max_lines =~ ^
[0-9]+$
]] ||
{ echo "error in hl: failed to get max line count"; return 1; }
1047 linecount
=$
(wc -l < $HISTFILE) # pipe so it doesnt output a filename
1048 [[ $linecount =~ ^
[0-9]+$
]] ||
{ echo "error in hl: wc failed"; return 1; }
1049 if (($linecount > $max_lines)); then
1050 prune_lines
=$
(($linecount - $max_lines))
1051 head -n $prune_lines "$HISTFILE" >> "$harchive" \
1052 && sed --follow-symlinks -ie "1,${prune_lines}d" $HISTFILE
1056 hr
() { # horizontal row. used to break up output
1057 printf "$(tput setaf 5)â–ˆ$(tput sgr0)%.0s" $
(seq ${COLUMNS:-60})
1061 hrcat
() { local f
; for f
; do [[ -f $f ]] ||
continue; hr
; echo "$f"; cat "$f"; done }
1063 # get latest hub and run it
1064 # main command to use:
1065 # hub pull-request --no-edit
1066 # --no-edit means to use the first commit\'s message as the pull request message.
1067 # Also, you need to use a feature branch, not master in your fork.
1068 # On first use, you input username/pass and it gets an oath token so you dont have to repeat
1069 # it\'s at ~/.config/hub
1071 local up uptar updir p
1072 p
=/github
/hub
/releases
/
1073 up
=https
://github.com
/$
(curl
-s https
://github.com
$p|
grep -o $p'download/[^/]*/hub-linux-amd64[^"]*' |
head -n1)
1076 if [[ ! -e /a
/opt
/$updir ]]; then
1077 rm -rf /a
/opt
/hub-linux-amd64
*
1079 tar -C /a
/opt
-zxf /a
/opt
/$uptar
1081 s
/a
/opt
/$updir/install
1084 # save token across computers
1085 if [[ ! -L ~
/.config
/hub
]]; then
1086 if [[ -e ~
/.config
/hub
]]; then
1087 mv ~
/.config
/hub
/p
/c
/subdir_files
/.config
/
1089 if [[ -e /p
/c
/subdir_files
/.config
/hub
]]; then
1097 # modified from ~/local/bin/git-completion.bash
1098 # other completion commands are mostly taken from bash_completion package
1099 complete
-o bashdefault
-o default
-o nospace
-F _git i
2>/dev
/null \
1100 || complete
-o default
-o nospace
-F _git i
1102 if ! type service
&>/dev
/null
; then
1104 echo actually running
: systemctl
$2 $1
1116 /a
/opt
/idea-IC-163.7743
.44/bin
/idea.sh
"$@" &r
1121 find -L .
-not \
( -name .svn
-prune -o -name .git
-prune \
1122 -o -name .hg
-prune -o -name .editor-backups
-prune \
1123 -o -name .undo-tree-history
-prune \
) -iname "*$**" 2>/dev
/null
1128 if type gvfs-open
&> /dev
/null
; then
1133 # another alternative is run-mailcap
1137 s iptables
-A INPUT
-s $1 -j DROP
1142 grep -Il "" "$@" &>/dev
/null
1146 grep -Evi -e "^(\S+\s+){4}(sudo|sshd|cron)\[\S*:" \
1147 -e "^(\S+\s+){4}systemd\[\S*: (starting|started) (btrfsmaintstop|dynamicipupdate|spamd dns bug fix cronjob|rss2email)\.*$"
1150 journalctl
-n 10000 -f "$@" | jfilter
1152 jr
() { journalctl
"$@" | jfilter |
less ; }
1153 jrf
() { journalctl
-f "$@" | jfilter
; }
1155 kff
() { # keyboardio firmware flash
1156 pushd /a
/bin
/distro-setup
/Arduino
/Model01-Firmware
1157 yes $
'\n' |
make flash
1162 if [[ $PWD == /[iap
] ]]; then
1163 command ls -A --color=auto
-I lost
+found
"$@"
1165 command ls -A --color=auto
"$@"
1170 lcn
() { locate -i "*$**"; }
1172 lg
() { LC_COLLATE
=C.UTF-8 ll
--group-directories-first; }
1174 lt
() { ll
-tr "$@"; }
1176 lld
() { ll
-d "$@"; }
1180 if [[ $1 == /* ]]; then
1182 if mountpoint
/mnt
/$base; then
1185 l
=$
(sudo losetup
-f)
1187 if ! sudo cryptsetup luksOpen
$l $base; then
1191 sudo mkdir
-p /mnt
/$base
1192 sudo mount
/dev
/mapper
/$base /mnt
/$base
1193 sudo chown
$USER:$USER /mnt
/$base
1196 sudo umount
/mnt
/$base
1197 l
=$
(sudo cryptsetup status
/dev
/mapper
/$base|
sed -rn 's/^\s*device:\s*(.*)/\1/p')
1198 sudo cryptsetup luksClose
/dev
/mapper
/$base ||
return 1
1203 low
() { # make filenames lowercase, remove bad chars
1206 new
="${f,,}" # downcase
1207 new
="${new//[^[:alnum:]._-]/_}" # sub bad chars
1208 new
="${new#"${new%%[[:alnum:]]*}"}" # remove leading/trailing non-alnum
1209 new
="${new%"${new##*[[:alnum:]]}"}"
1210 # remove bad underscores, like __ and _._
1211 new
=$
(echo $new |
sed -r 's/__+/_/g;s/_+([.-])|([.-])_+/\1/g')
1212 safe_rename
"$f" "$new" ||
return 1
1217 lower
() { # make first letter of filenames lowercase.
1220 if [[ ${x::1} == [A-Z
] ]]; then
1221 y
=$
(tr "[A-Z]" "[a-z]" <<<"${x::1}")"${x:1}"
1222 safe_rename
"$x" "$y" ||
return 1
1228 k
() { # history search
1229 grep -P --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
tail -n 80;
1232 ks
() { # history search
1233 grep -P --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
uniq;
1238 # show make targets, via http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make
1239 make -qp |
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
1247 [[ -e $src ]] ||
{ set +x
; return 1; }
1248 mv -T $src $dst ||
{ set +x
; return 1; }
1251 mu index
--maildir=/m
/4e
1259 [[ -e $src ]] ||
{ set +x
; return 1; }
1260 if [[ -L $dst ]]; then rm $dst; fi
1267 markdown
"$1" >/tmp
/mdtest.html
1268 firefox
/tmp
/mdtest.html
1281 mkt
() { # mkdir and touch file
1283 mkdir
-p "$(dirname "$path")"
1287 mkdir
() { command mkdir
-p "$@"; }
1289 mo
() { xset dpms force off
; } # monitor off
1292 e
"lspci -nnk|gr -iA2 net"
1293 lspci
-nnk|gr
-iA2 net
1295 e
"s lshw -C network"
1302 ser stop NetworkManager
1304 s resolvconf
-d NetworkManager
1310 ser start NetworkManager
1316 sudo
tee -a /var
/log
/exim
4/paniclog-archive
</var
/log
/exim
4/paniclog
; sudo truncate
-s0 /var
/log
/exim
4/paniclog
1321 oathtool
--totp -b "$@" | xclip
-selection clipboard
1324 p8
() { ping 8.8.8.8; }
1327 # from http://askubuntu.com/questions/456021/remove-vocals-from-mp3-and-get-only-instrumentals
1328 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
1332 pfind
() { #find *$1* in $PATH
1333 [[ $# != 1 ]] && { echo requires
1 argument
; return 1; }
1335 IFS
=: pathArray
=($PATH); unset IFS
1336 find "${pathArray[@]}" -iname "*$1*"
1339 pkx
() { # package extract
1342 cached
=$
(ls -t /var
/cache
/apt
/archives
/$pkg* |
tail -n1)
1343 if [[ $cached ]]; then
1346 aptitude download
$pkg
1355 pid
=($
(pgrep
-f "$*"))
1361 0) echo "no pid found" ;;
1369 # trash-restore lists everything that has been trashed at or below CWD
1370 # This picks out files just in CWD, not subdirectories,
1371 # which also match grep $1, usually use $1 for a time string
1372 # which you get from running restore-trash once first
1375 # last condition is to not ask again for ones we skipped
1376 while name
="$( echo | restore-trash | gr "$PWD/[^
/]\
+$
" | gr "$1" )" \
1377 && [[ $name ]] && (( $
(wc -l <<<"$name") >= nth
)); do
1378 name
="$(echo "$name" | head -n $nth | tail -n 1 )"
1379 read -p "$name [Y/n] " ask
1380 if [[ ! $ask ||
$ask == [Yy
] ]]; then
1381 x
=$
( echo "$name" | gr
-o "^\s*[0-9]*" )
1382 echo $x | restore-trash
> /dev
/null
1383 elif [[ $ask == [Nn
] ]]; then
1393 rld
/a
/h
/_site
/ li
:/var
/www
/iankelling.org
/html
1396 pubip
() { curl
-4s https
://icanhazip.com
; }
1397 pubip6
() { curl
-6s https
://icanhazip.com
; }
1398 whatismyip
() { pubip
; }
1401 # fixes the menu bar in xmonad. this won\'t be needed when xmonad
1402 # packages catches up on some changes in future (this is written in
1405 # geekosaur: so youll want to upgrade to xmonad 0.13 or else use a
1406 # locally modified XMonad.Hooks.ManageDocks that doesnt set the
1407 # work area; turns out it\'s impossible to set correctly if you are
1408 # not a fully EWMH compliant desktop environment
1410 # geekosaur: chrome shows one failure mode, qt/kde another, other
1411 # gtk apps a third, ... I came up with a setting that works for me
1412 # locally but apparently doesnt work for others, so we joined the
1413 # other tiling window managers in giving up on setting it at all
1415 xprop
-root -remove _NET_WORKAREA
1423 # -t = print pronunciation
1425 for (( i
=0; i
<10; i
++ )); do
1426 shuf
-n3 /usr
/share
/hunspell
/en_US.dic |
sed 's,/.*,,' |
paste -sd .
-
1432 # -M CLN = use Caps, Lowercase, Numbers
1434 # -a 1 = use random instead of pronounceable algorithm
1435 apg
-m 50 -x 70 -n 1 -a 1 -M CLN
1439 q
() { # start / launch a program in the backround and redir output to null
1446 # i had this redir, not sure why
1447 # exit "$@" 2>/dev/null
1450 rbpipe
() { rbt post
-o --diff-filename=- "$@"; }
1451 rbp
() { rbt post
-o "$@"; }
1462 hr
; echo dnsmasq is $
(systemctl is-active dnsmasq
)
1463 f
=/var
/run
/dnsmasq
/resolv.conf
1464 hr
; echo $f:; ccat
$f
1465 f
=/etc
/dnsmasq-servers.conf
1466 hr
; echo $f:; ccat
$f
1470 # rsync, root is required to keep permissions right.
1471 # rsync --archive --human-readable --verbose --itemize-changes --checksum \(-ahvic\) \
1472 # --no-times --delete
1473 # basically, make an exact copy, use checksums instead of file times to be more accurate
1474 rsync
-ahvic --delete "$@"
1477 # like rlu, but dont delete files on the target end which
1478 # do not exist on the original end.
1481 complete
-F _rsync
-o nospace rld rl rlt
1484 # rl without preserving modification time.
1485 rsync
-ahvic --delete --no-t "$@"
1488 rlu
() { # [OPTS] HOST PATH
1489 # eg. rlu -opts frodo /testpath
1490 # relative paths will expanded with readlink -f.
1491 # useful for selectively sending dirs which have been synced with unison,
1492 # where the path is the same on both hosts.
1493 opts
=("${@:1:$#-2}") # 1 to last -2
1494 path
="${@:$#}" # last
1495 host="${@:$#-1:1}" # last -1
1496 if [[ $path == .
* ]]; then
1497 path
=$
(readlink
-f $path)
1499 # rync here uses checksum instead of time so we dont mess with
1500 # unison relying on time as much. g is for group, same reason
1501 # to keep up with unison.
1502 s rsync
-rlpchviog --relative "${opts[@]}" "$path" "root@$host:/";
1505 # only run on MAIL_HOST. simpler to keep this on one system.
1506 r2eadd
() { # usage: name url
1507 # initial setup of rss2email:
1508 # r2e new r2e@iankelling.org
1509 # that initializes files, and sets default email.
1510 # symlink to the config doesnt work, so I copied it to /p/c
1511 # and then use cli option to specify explicit path.
1512 # Only option changed from default config is to set
1515 # or else for a few feeds, the from address is set by the feed, and
1516 # if I fail delivery, then I send a bounce message to that from
1517 # address, which makes me be a spammer.
1519 r2e add
$1 "$2" $1@r2e.iankelling.org
1520 # get up to date and dont send old entries now:
1521 r2e run
--no-send $1
1523 r2e
() { command r2e
-d /p
/c
/rss2email.json
-c /p
/c
/rss2email.cfg
"$@"; }
1525 rspicy
() { # usage: HOST DOMAIN
1526 # connect to spice vm remote host. use vspicy for local host
1527 local port
=$
(ssh $1<<EOF
1528 sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
1529 sed -rn "s/.*port='([0-9]+).*/\1/p"
1532 if [[ $port ]]; then
1533 spicy
-h $1 -p $port
1535 echo "error: no port found. check that the domain is running."
1540 ssh fencepost
head -n 300 /gd
/gnuorg
/EventAndTravelInfo
/rms-current-trips.txt |
less
1545 # I use a function because otherwise we cant use in a script,
1546 # cant assign to variable.
1548 # note: gksudo is recommended for X apps because it does not set the
1549 # home directory to the same, and thus apps writing to ~ fuck things up
1550 # with root owned files.
1552 if [[ $EUID != 0 ||
$1 == -* ]]; then
1553 SUDOD
="$PWD" sudo
-i "$@"
1559 safe_rename
() { # warn and dont rename if file exists.
1560 # mv -n exists, but it\'s silent
1561 if [[ $# != 2 ]]; then
1562 echo safe_rename error
: $# args
, need
2 >2
1565 if [[ $1 != $2 ]]; then # yes, we want to silently ignore this
1566 if [[ -e $2 ||
-L $2 ]]; then
1567 echo "Cannot rename $1 to $2 as it already exists."
1575 sb
() { # sudo bash -c
1576 # use sb instead of s is for sudo redirections,
1577 # eg. sb 'echo "ok fine" > /etc/file'
1579 sudo
-i bash
-c "$@"
1581 complete
-F _root_command s sb
1584 # s gem install scss-lint
1585 pushd /a
/opt
/thoughtbot-guides
1588 scss-lint
-c /a
/opt
/thoughtbot-guides
/style
/sass
/.scss-lint.yml
"$@"
1592 local s
; [[ $EUID != 0 ]] && s
=s
1593 if type -p systemctl
&>/dev
/null
; then
1599 # like restart, but do nothing if its not already started
1602 if [[ $
(s systemctl
--no-pager show
-p ActiveState
$service ) == ActiveState
=active
]]; then
1603 systemctl restart
$service
1607 setini
() { # set a value in a .ini style file
1608 key
="$1" value
="$2" section
="$3" file="$4"
1609 if [[ -s $file ]]; then
1610 sed -ri -f - "$file" <<EOF
1611 # remove existing keys
1612 / *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d}
1614 /^\s*\[$section\]/a $key=$value
1615 # from section to eof, do nothing
1616 /^\s*\[$section\]/,\$b
1617 # on the last line, if we haven't found section yet, add section and key
1629 sgo
() { # service go
1631 ser restart
$service ||
return 1
1632 if type -p systemctl
&>/dev
/null
; then
1639 # 2086 = unquoted $var
1640 # 2046 = unquoted $(cmd)
1641 # i had -x as an arg, but debian testing(stretch) doesn\'t support it
1642 shellcheck
-e 2086,2046,2068,2006,2119 "$@"
1648 out
=${2:-${1%.*}.sh}
1650 script -t -c "mpv --no-config --no-resume-playback --no-terminal --no-audio-display '$1'" $tmp/typescript
2>$tmp/timing
1651 # todo, the current sleep seems pretty good, but it
1652 # would be nice to have an empirical measurement, or
1653 # some better wait to sync up.
1655 # note: --loop-file=no prevents it from hanging if you have that
1656 # set to inf the mpv config.
1657 # --loop=no prevents it from exit code 3 due to stdin if you
1658 # had it set to inf in mpv config.
1660 # args go to mpv, for example --volume=80, 50%
1661 cat >$out <<EOFOUTER
1663 trap "trap - TERM && kill 0" INT TERM ERR; set -e
1664 ( sleep .2; scriptreplay <( cat <<'EOF'
1668 $(cat $tmp/typescript)
1671 base64 -d - <<'EOF'| mpv --loop=no --loop-file=no --no-terminal --no-audio-display "\$@" -
1681 # log with script. timing is $1.t and script is $1.s
1682 # -l to save to ~/typescripts/
1683 # -t to add a timestamp to the filenames
1684 local logdir do_stamp arg_base
1685 (( $# >= 1 )) ||
{ echo "arguments wrong"; return 1; }
1688 while getopts "lt" option
1691 l
) arg_base
=$logdir ;;
1692 t
) do_stamp
=true
;;
1695 shift $
(($OPTIND - 1))
1697 [[ -e $logdir ]] || mkdir
-p $logdir
1698 $do_stamp && arg_base
+=$
(date +%F.
%T
%z
)
1699 script -t $arg_base.s
2> $arg_base.t
1701 splay
() { # script replay
1702 #logRoot="$HOME/typescripts/"
1703 #scriptreplay "$logRoot$1.t" "$logRoot$1.s"
1704 scriptreplay
"$1.t" "$1.s"
1707 smeld
() { # ssh meld usage host1 host2 file
1708 meld
<(ssh $1 cat $3) <(ssh $2 cat $3)
1712 PATH
=/usr
/local
/spdhackfix
:$PATH command spd
"$@"
1720 # sudo redo. be aware, this command may not work right on strange distros or earlier software
1721 if [[ $# == 0 ]]; then
1722 sudo
-E bash
-c -l "$(history -p '!!')"
1724 echo this
command redos last
history item. no argument is accepted
1729 # with -ll, less secure but faster.
1730 command srm
-ll "$@"
1735 ssh $1 /tmp
/${2##*/} "${@:2}"
1739 BASH_LOGIN_SHELL
=true
command ssh "$@"
1742 ssh -oControlMaster=no
-oControlPath=/ "$@"
1746 while [[ $1 == -* ]]; do
1750 m pkill
-f "^ssh: /tmp/ssh_mux_${USER}_${1#*@}_22_"
1751 m
ssh "${opts[@]}" "$@"
1765 if type -t trash-put
>/dev
/null
; then
1766 # skip args that dont exist, or else trash-put will have an error
1768 if [[ -e $x ||
-L $x ]]; then
1772 [[ ! ${args[@]} ]] || trash-put
"${args[@]}"
1783 # this goes to full width
1784 #len=${1:-$((COLUMNS -7))}
1787 if (( x
== len
)); then
1789 d
="$(date +%l:%_M) "
1792 d
=$
(date +%l
:%M
:%_S
)
1796 for ((i
=0; i
<x
; i
++)); do
1797 if (( i
% 6 )); then
1815 # test existence / exists
1818 [[ -e "$x" ||
-L "$x" ]] || ret
=1
1825 declare -gi _seq
; _seq
+=1
1826 echo "test body" | m
mail -s "test mail from $HOSTNAME, $_seq" "${@:-root@localhost}"
1827 # for testing to send from an external address, you can do for example
1828 # -fian@iank.bid -aFrom:ian@iank.bid web-6fnbs@mail-tester.com
1829 # note in exim, you can retry a deferred message
1831 # MSG_ID is in /var/log/exim4/mainlog, looks like 1ccdnD-0001nh-EN
1834 # to test sieve, use below command. for fsf mail, see offlineimap-sync script
1835 # make modifications, then copy to live file, use -eW to actually modify mailbox
1837 # Another option is to use sieve-test SCRIPT MAIL_FILE. note,
1838 # sieve-test doesnt know about envelopes, Im not sure if sieve-filter does.
1840 # sieve with output filter. arg is mailbox, like INBOX.
1841 # This depends on dovecot conf, notably mail_location in /etc/dovecot/conf.d/10-mail.conf
1844 sieve-filter
"$@" 2> >(head; tail) >/tmp
/testsieve.log
&& sed -rn '/^Performed actions:/,/^[^ ]/{/^ /p}' /tmp
/testsieve.log |
sort |
uniq -c
1847 # always run this first, edit the test files, then run the following
1849 _dosieve ~
/sieve
/maintest.sieve
${1:-INBOX} delete
1852 c ~
/sieve
; cp personal
{test,}.sieve
; cp lists
{test,}.sieve
; cp personalend
{test,}.sieve
1853 _dosieve ~
/sieve
/main.sieve
-eW ${1:-INBOX} delete
1858 # testmail above calls sendmail, which is a link to exim/postfix.
1859 # its docs dont say a way of adding an argument
1860 # to sendmail to turn on debug output. We could make a wrapper, but
1861 # that is a pain. Exim debug args are documented here:
1862 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
1864 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-building_and_installing_exim.html
1865 # note, for exim daemon, you can turn on debug options by
1866 # adding -d, etc to COMMONOPTIONS in
1867 # /etc/default/exim4
1869 From: ian@iankelling.org
1870 To: root@lists0p.fsf.org
1871 Subject: Testing Exim
1873 This is a test message.
1880 # https://askubuntu.com/questions/160945/is-there-a-way-to-disable-a-laptops-internal-keyboard
1881 id
=$
(xinput
--list --id-only 'AT Translated Set 2 keyboard')
1882 if xinput list |
grep -F '∼ AT Translated Set 2 keyboard' &>/dev
/null
; then
1883 echo enabling keyboard
1884 # find the first slave keyboard number, they are all the same in my output.
1885 # if they werent, worst case we would need to save the slave number somewhere
1886 # when it got disabled.
1887 slave
=$
(xinput list |
sed -n 's/.*slave \+keyboard (\([0-9]*\)).*/\1/p' |
head -n1)
1888 xinput reattach
$id $slave
1897 (sleep $
(calc
"$@ * 60") && mpv
--no-config --volume 50 /a
/bin
/data
/alarm.mp3
) > /dev
/null
2>&1 &
1900 trg
() { transmission-remote-gtk
&r
; }
1902 # example, set global upload limit to 100 kilobytes:
1904 TR_AUTH
=":$(jq -r .profiles[0].password ~/.config/transmission-remote-gtk/config.json)" transmission-remote transmission.lan
-ne "$@"
1910 local dir
="$(dirname "$1")"
1911 if [[ -e $1 && ! -w $1 ||
! -w $
(dirname "$1") ]]; then
1917 tx
() { # toggle set -x, and the prompt so it doesnt spam
1918 if [[ $
- == *x
* ]]; then
1920 PROMPT_COMMAND
=prompt-command
1921 # disabled due to issue on stretch, running ll we get error. something
1922 # about the DEBUG trap is broken
1923 # if [[ $TERM == *(screen*|xterm*|rxvt*) ]]; then
1924 # trap 'settitle "$BASH_COMMAND"' DEBUG
1927 # normally, i would just execute these commands in the function.
1928 # however, DEBUG is not inherited, so we need to run it outside a function.
1929 # And we want to run set -x afterwards to avoid spam, so we cram everything
1930 # in here, and then it will run after this function is done.
1931 #PROMPT_COMMAND='trap DEBUG; unset PROMPT_COMMAND; PS1="\w \$ "; set -x'
1933 unset PROMPT_COMMAND
1940 # show all processes in the network namespace $1.
1941 # blank entries appear to be subprocesses/threads
1945 s
find -L /proc
/[1-9]*/task
/*/ns
/net
-samefile /run
/netns
/$netns | cut
-d/ -f5 | \
1947 x
=$
(ps
-w --no-headers -p $l);
1948 if [[ $x ]]; then echo "$x"; else echo $l; fi;
1952 m
() { printf "%s\n" "$*"; "$@"; }
1955 #m s nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*pia.conf") -n -m "$@"
1956 m s nsenter
-t $
(pgrep
-f "/usr/sbin/openvpn .* --config /etc/openvpn/.*client.conf") -n -m "$@"
1959 vpncmd gksudo
-u iank
"firefox -no-remote -P vpn" &r
1962 vpncmd gksudo
-u iank
"$*"
1971 for x
in "$@"; do virsh destroy
"$x"; virsh undefine
"$x"; done
1978 s virsh dumpxml
$vm |
sed -r "s/(<listen.*address=')([^']+)/\1$ip/" | \
1979 sed -r "s/listen='[^']+/listen='$ip/"> $t
1980 s virsh undefine
$vm
1986 vm-set-listen
$1 0.0.0.0
1991 vm-set-listen
$1 127.0.0.1
1996 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
1997 local vpn_service
=openvpn-client
1999 local vpn_service
=openvpn
2002 [[ $1 ]] ||
{ echo need arg
; return 1; }
2003 journalctl
--unit=$vpn_service@
$1 -f -n0 &
2004 s systemctl start
$vpn_service@
$1
2005 # sometimes the ask-password agent does not work and needs a delay.
2007 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779240
2008 # noticed around 8-2017 after update from around stretch release
2009 # on debian testing, even though the bug is much older.
2010 s systemd-tty-ask-password-agent
2014 [[ $1 ]] ||
{ echo need arg
; return 1; }
2015 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
2016 local vpn_service
=openvpn-client
2018 local vpn_service
=openvpn
2020 s systemctl stop
$vpn_service@
$1
2031 vspicy
() { # usage: VIRSH_DOMAIN
2032 # connect to vms made with virt-install
2033 spicy
-p $
(sudo virsh dumpxml
"$1"|
grep "<graphics.*type='spice'"|\
2034 sed -r "s/.*port='([0-9]+).*/\1/")
2038 cat-new-files
/m
/4e
/INBOX
/new
2041 wtr
() { curl wttr.in
/boston
; }
2043 xevkb
() { xev
-event keyboard
; }
2047 # from curl cheat.sh/:bash_completion
2048 _cheatsh_complete_curl
()
2051 _get_comp_words_by_ref
-n : cur
2054 #cur="${COMP_WORDS[COMP_CWORD]}"
2055 prev
="${COMP_WORDS[COMP_CWORD-1]}"
2056 opts
="$(curl -s cheat.sh/:list | sed s@^@cheat.sh/@)"
2058 if [[ ${cur} == cheat.sh
/* ]] ; then
2059 COMPREPLY
=( $
(compgen
-W "${opts}" -- ${cur}) )
2060 __ltrim_colon_completions
"$cur"
2064 complete
-F _cheatsh_complete_curl curl
2067 if [[ $
- == *i
* ]]; then
2068 # commands to run when bash exits normally
2073 # temporary variables to test colorization
2074 # some copied from gentoo /etc/bash/bashrc,
2076 # dircolors --print-database uses its own built-in database
2077 # instead of using /etc/DIR_COLORS. Try to use the external file
2078 # first to take advantage of user additions.
2079 safe_term
=${TERM//[^[:alnum:]]/?} # sanitize TERM
2081 [[ -f ~
/.dir_colors
]] && match_lhs
="${match_lhs}$(<~/.dir_colors)"
2082 [[ -f /etc
/DIR_COLORS
]] && match_lhs
="${match_lhs}$(</etc/DIR_COLORS)"
2083 [[ -z ${match_lhs} ]] \
2084 && type -P dircolors
>/dev
/null \
2085 && match_lhs
=$
(dircolors
--print-database)
2086 # test if our $TERM is in the TERM values in dircolor
2087 [[ $
'\n'${match_lhs} == *$
'\n'"TERM "${safe_term}* ]] && use_color
=true
2090 if ${use_color} && [[ $
- == *i
* ]]; then
2092 term_underl
="$(tput smul)"
2093 term_bold
="$(tput bold)"
2094 term_red
="$(tput setaf 1)"
2095 term_green
="$(tput setaf 2)"
2096 term_blue
="$(tput setaf 4)"
2097 term_cyan
="$(tput setaf 6)"
2098 term_yellow
="$(tput setaf 3)"
2099 term_purple
="$(tput setaf 5)"
2100 term_nocolor
="$(tput sgr0)" # no font attributes
2103 # Try to keep environment pollution down, EPA loves us.
2104 unset safe_term match_lhs use_color
2111 if [[ $
- == *i
* ]]; then
2112 # git branch/status prompt function
2113 if [[ $OS != Windows_NT
]]; then
2114 GIT_PS1_SHOWDIRTYSTATE
=true
2116 # arch source lopip show -fcation
2117 [[ -r /usr
/share
/git
/git-prompt.sh
]] && source /usr
/share
/git
/git-prompt.sh
2118 # fedora/debian source
2119 [[ -r /usr
/share
/git-core
/contrib
/completion
/git-prompt.sh
]] && source /usr
/share
/git-core
/contrib
/completion
/git-prompt.sh
2121 # in case we didnt source git-prompt.sh
2122 if ! declare -f __git_ps1
> /dev
/null
; then
2128 # this needs to come before next ps1 stuff
2129 # this stuff needs bash 4, feb 2009,
2130 # old enough to no longer condition on $BASH_VERSION anymore
2134 if [[ $
- == *i
* ]] && [[ ! $RLC_INSIDE_EMACS ]]; then
2136 bind -m vi-command B
:shell-backward-word
2137 bind -m vi-command W
:shell-forward-word
2140 if [[ $SSH_CLIENT ||
$SUDO_USER ]]; then
2144 # emacs terminal has problems if this runs slowly,
2145 # so I've thrown a bunch of things at the wall to speed it up.
2147 local return=$?
# this MUST COME FIRST
2148 local psc pst ps_char ps_color stale_subvol
2150 history -a # save history
2153 0) ps_color
="$term_purple"
2156 1) ps_color
="$term_green"
2157 ps_char
="$return \\$"
2159 *) ps_color
="$term_yellow"
2160 ps_char
="$return \\$"
2163 if [[ ! -O .
]]; then # not owner
2164 if [[ -w .
]]; then # writable
2165 ps_color
="$term_bold$term_red"
2167 ps_color
="$term_bold$term_green"
2171 # faster than sourceing the file im guessing
2172 eval $
(< /dev
/shm
/iank-status
)
2173 if [[ ! $SSH_CLIENT && $MAIL_HOST != $HOSTNAME ]]; then
2174 ps_char
="@ $ps_char"
2176 PS1
="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$term_nocolor\] "
2178 PROMPT_COMMAND
=prompt-command
2181 if [[ $TERM == screen
* ]]; then
2182 local title_escape
="\033]..2;"
2184 local title_escape
="\033]0;"
2186 if [[ $
* != prompt-command
]]; then
2187 echo -ne "$title_escape$USER@$HOSTNAME ${PWD/#$HOME/~} "
2194 # condition from the screen man page i think.
2195 # note: duplicated in tx()
2196 # disabled. see note in tx
2197 # if [[ $TERM == *(screen*|xterm*|rxvt*) ]]; then
2198 # trap 'settitle "$BASH_COMMAND"' DEBUG
2206 # we also have a file in /a/c/...konsole...
2207 local f
=$HOME/.config
/konsolerc
2208 setini DefaultProfile profileian.profile
"Desktop Entry" $f
2209 setini Favorites profileian.profile
"Favorite Profiles" $f
2210 setini ShowMenuBarByDefault false KonsoleWindow
$f
2211 setini TabBarPosition Top TabBar
$f
2216 setini
$k $v sakura
/a
/c
/subdir_files
/.config
/sakura
/sakura.conf
2218 colorset1_back rgb(33,37,39
2222 disable_numbered_tabswitch true
2223 scroll_lines 10000000
2228 reset-xscreensaver
() {
2229 # except for spash, i set these by setting gui options in
2230 # xscreensaver-command -demo
2231 # then finding the corresponding option in .xscreensaver
2232 # spash, i happened to notice in .xscreensaver
2234 # dpmsOff, monitor doesnt come back on using old free software supported nvidia card
2235 cat > /home
/iank
/.xscreensaver
<<'EOF'
2238 dpmsStandby: 0:02:00
2239 dpmsSuspend: 0:03:00
2243 lockTimeout: 0:03:00
2250 # * stuff that makes sense to be at the end
2251 if [[ "$SUDOD" ]]; then
2254 elif [[ -d /a
]] && [[ $PWD == $HOME ]] && [[ $
- == *i
* ]]; then
2263 # for mitmproxy to get a newer python.
2264 # commented until i want to use it because it
2265 # noticably slows bash startup
2269 if [[ $EUID == 0 ||
! -e ~
/.pyenv
/bin
]]; then
2270 echo "error: dont be root. make sure pyenv is installed"
2273 export PATH
="~/.pyenv/bin:$PATH"
2274 eval "$(pyenv init -)"
2275 eval "$(pyenv virtualenv-init -)"
2279 export GOPATH
=$HOME/go
2280 path_add
$GOPATH/bin
2281 path_add
/usr
/local
/go
/bin
2283 # I have the git repo and a release. either one should work.
2284 # I have both because I was trying to solve an issue that
2285 # turned out to be unrelated.
2286 # ARDUINO_PATH=/a/opt/Arduino/build/linux/work
2287 export ARDUINO_PATH
=/a
/opt
/arduino-1.8
.9
2289 # They want to be added to the start, but i think
2290 # that should be avoided unless we really need it.
2291 path_add
--end ~
/.npm-global
2293 path_add
--end $HOME/.cargo
/bin
2295 # taken from default changes to bashrc and bash_profile
2296 path_add
--end $HOME/.rvm
/bin
2297 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
2299 export BASEFILE_DIR
=/a
/bin
/fai-basefiles
2301 export ANDROID_HOME
=/opt
/android
2303 # didnt get drush working, if I did, this seems like the
2304 # only good thing to include for it.
2305 # Include Drush completion.
2306 # if [ -f "/home/ian/.drush/drush.complete.sh" ] ; then
2307 # source /home/ian/.drush/drush.complete.sh
2311 # https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
2312 # i added an extra condition as gentoo xorg guide says depending on
2313 # $DISPLAY is fragile.
2314 if [[ ! $DISPLAY && $XDG_VTNR == 1 ]] && shopt -q login_shell
&& isarch
; then
2319 # ensure no bad programs appending to this file will have an affect