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 # todo: not sure this works in sakura
112 #bind "\C-w": kill-region
113 # sakura == xterm-256color
115 if [[ $TERM == "xterm" ]]; then
116 # control + arrow keys. for other terminals, see http://unix.stackexchange.com/questions/10806/how-to-change-previous-next-word-shortcut-in-bash
117 bind '"\e[1;5C": shell-forward-word' 2>/dev
/null
118 bind '"\e[1;5D": shell-backward-word' 2>/dev
/null
120 # make ctrl-backspace work. for konsole, i fixed it through
121 # /home/iank/.local/share/konsole/default.keytab
123 bind '"\eOc": shell-forward-word'
124 bind '"\eOd": shell-backward-word'
126 # i cant remember why i did this, probably to free up some keys to bind
127 # to other things in bash.
128 # other than C-c and C-z, the rest defined by stty -a are, at least in
129 # gnome-terminal, overridden by bash, or disabled by the system
130 stty lnext undef stop undef start undef
136 # history number. History expansion is good.
138 # history file size limit, set to unlimited.
139 # this needs to be different from the default because
140 # default HISTFILESIZE is 500 and could clobber our history
142 # max commands 1 session can append/read from history
144 # my own history size limit based on lines
145 HISTFILELINES
=1000000
147 # the time format display when doing the history command
148 # also, setting this makes the history file record time
149 # of each command as seconds from the epoch
150 HISTTIMEFORMAT
="%Y-%m-%d %I:%M %p "
151 # consecutive duplicate lines dont go in history
152 HISTCONTROL
=ignoredups
153 # works in addition to HISTCONTROL to do more flexible things
154 # it could also do the same things as HISTCONTROL and thus replace it,
155 # but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
156 HISTIGNORE
='pass *:[ ]*:lom*:gram*'
158 export BC_LINE_LENGTH
=0
160 export PROFILE_TASKS_TASK_OUTPUT_LIMIT
=100
162 # note, if I use a machine I dont want files readable by all users, set
163 # umask 077 # If fewer than 4 digits are entered, leading zeros are assumed
167 # i for insensitive. the rest from
168 # https://superuser.com/questions/366930/how-do-i-get-the-git-pager-to-clean-up-screen-output-after-exit
169 # and reading the man
171 export SYSTEMD_LESS
=$LESS
174 for _x
in /a
/bin
/distro-functions
/src
/* /a
/bin
/!(githtml
)/*-function?
(s
); do
178 # so I can share my bashrc
179 for x
in /a
/bin
/bash_unpublished
/source-
!(.
#*); do source $x; done
180 source $
(dirname $
(readlink
-f $BASH_SOURCE))/path_add-function
181 source /a
/bin
/log-quiet
/logq-function
182 if [[ -e /a
/bin
/errhandle
/err
]]; then
183 source /a
/bin
/errhandle
/err
186 # if someone exported $SOE (stop on error), catch errors
192 # add this with absolute paths as needed for better security
193 #path_add --end /path/to/node_modules/.bin
195 # pip3 --user things go here:
196 path_add
--end ~
/.local
/bin
197 path_add
--ifexists --end /a
/work
/libremanage
198 path_add
--ifexists --end /a
/opt
/adt-bundle
*/tools
/a
/opt
/adt-bundle
*/platform-tools
199 path_add
--ifexists --end /a
/opt
/scancode-toolkit-2.9
.2
201 # based on readme.debian. dunno if this will break on other distros.
202 _x
=/usr
/share
/wcd
/wcd-include.sh
203 if [[ -e $_x ]]; then source $_x; fi
208 # very few aliases, functions are always preferred.
211 if [[ $OS == Windows_NT
]]; then
212 alias ffs
='cygstart "/c/Program Files (x86)/Mozilla Firefox/firefox.exe" -P scratch'
214 alias j
='command cygpath'
215 alias t
='command cygstart'
216 alias cygstart
='echo be quick, use the alias "t" instead :\)'
217 alias cygpath
='echo be quick, use the alias "j" instead :\)'
222 # keep this in mind? good for safety.
227 # remove any default aliases for these
228 unalias ls ll
grep &>/dev
/null ||
:
237 ....
() { c ..
/..
/..
; }
238 .....
() { c ..
/..
/..
/..
; }
239 ......
() { c ..
/..
/..
/..
/..
; }
242 # file cut copy and paste, like the text buffers :)
243 # I havnt tested these.
244 _fbufferinit
() { # internal use by
245 ! [[ $my_f_tempdir ]] && my_f_tempdir
=$
(mktemp
-d)
246 rm -rf "$my_f_tempdir"/*
250 cp "$@" "$my_f_tempdir"/
254 mv "$@" "$my_f_tempdir"/
256 fpst
() { # file paste
257 [[ $2 ]] && { echo too many arguments
; return 1; }
259 cp "$my_f_tempdir"/* "$target"
264 complete
-F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr
268 # join options which are continued to multiples lines onto one line
270 grep -vE '^([ \t]*#|^[ \t]*$)' "$1" |
while IFS
= read -r line
; do
271 # remove leading spaces/tabs. assumes extglob
272 if [[ $line == "[ ]*" ]]; then
278 elif [[ $line == *=* ]]; then
279 echo "$pastline" >> "$2"
282 pastline
="$pastline $line"
285 echo "$pastline" >> "$2"
291 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")
293 echo "khfix: ssh failed"
296 if [[ $port != 22 ]]; then
297 ip_entry
="[$ip]:$port"
298 host_entry
="[$host]:$port"
303 ssh-keygen
-R "$host_entry" -f $
(readlink
-f ~
/.ssh
/known_hosts
)
304 echo "khfix: removing key for $ip_entry"
305 ssh-keygen
-R "$ip_entry" -f $
(readlink
-f ~
/.ssh
/known_hosts
)
307 khfix
() { # known hosts fix
308 _khfix_common
"$@" ||
return 1
317 local x
=$
(readlink
-nf "${1:-$PWD}")
318 # yes, its kinda dumb that xclip/xsel cant do this in one invocation
319 echo -n "$x" | xclip
-selection clipboard
323 ack
() { ack-grep
"$@"; }
326 if which anki
&>/dev
/null
; then
329 schroot
-c anki
-- anki
334 # pushd in case current directory has an ansible.cfg file
335 pushd /a
/xans
>/dev
/null
336 ansible-playbook
-v -l ${1:- $(hostname -f)} site.yml
340 pushd /a
/work
/ansible-configs
>/dev
/null
341 time ansible-playbook
-v -i inventory adhoc.yml
"$@"
345 pushd /a
/bin
/distro-setup
/a
>/dev
/null
346 ansible-playbook site.yml
351 # googling android emulator libGL error: failed to load driver: r600
352 # lead to http://stackoverflow.com/a/36625175/14456
353 export ANDROID_EMULATOR_USE_SYSTEM_LIBS
=1
354 /a
/opt
/android-studio
/bin
/studio.sh
"$@" &r
;
365 if systemctl is-active btrbk.service
; then
366 echo "cron btrbk is already running"
369 systemctl is-active btrbk.timer || active
=false
371 ser disable btrbk.timer
375 if ! btrbk-run
"$@" && $active; then
376 ser
enable btrbk.timer
380 bfg
() { java
-jar /a
/opt
/bfg-1.12
.14.jar
"$@"; }
383 xclock
-digital -update 1 -face 'arial black-80:bold'
391 switch-mail-host
$1 $HOSTNAME
398 switch-mail-host
$HOSTNAME $1
403 local f
=/etc
/bitcoin
/bitcoin.conf
404 # importprivkey will timeout if using the default of 15 mins.
405 # upped it to 1 hour.
406 bitcoin-cli
-rpcclienttimeout=60000 -$
(s
grep rpcuser
= $f) -$
(s
grep rpcpassword
= $f) "$@"
409 btcusd
() { # $1 btc in usd
411 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
412 printf "$%s\n" "$price"
414 printf "$%.2f\n" "$(echo "scale
=4; $price * $1"| bc -l)"
417 usdbtc
() { # $1 usd in btc
419 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
420 printf "$%s\n" "$price"
422 # 100 mil satoshi / btc. 8 digits after the 1.
423 printf "%.8f btc\n" "$(echo "scale
=10; $1 / $price "| bc -l)"
426 satoshi
() { # $1 satoshi in usd
428 price
="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
429 price
=$
(echo "scale=10; $price * 0.00000001"|
bc -l)
430 printf "$%f\n" "$price"
432 printf "$%.2f\n" "$(echo "scale
=10; $price * $1"| bc -l)"
438 if [[ $RLC_INSIDE_EMACS ]]; then
439 c
() { wcd
-c -z 50 -o "$@"; }
441 # lets see what the fancy terminal does from time to time
442 c
() { wcd
-c -z 50 "$@"; }
445 caa
() { git commit
--amend --no-edit -a; }
448 find -L $1 -type f
-not \
( -name .svn
-prune -o -name .git
-prune \
449 -o -name .hg
-prune -o -name .editor-backups
-prune \
450 -o -name .undo-tree-history
-prune \
) \
451 -exec bash
-lc 'hr; echo "$1"; hr; cat "$1"' _
{} \
; 2>/dev
/null
455 calc
() { echo "scale=3; $*" |
bc -l; }
456 # no having to type quotes, but also no command history:
460 echo "scale=3; $x" |
bc -l
467 cbfstool
() { /a
/opt
/coreboot
/build
/cbfstool
"$@"; }
469 ccat
() { # config cat. see a config without extra lines.
470 grep '^\s*[^;[:space:]#]' "$@"
475 # setup for format of postfix, eg:
479 local unified
="$(mktemp)"
482 _cdiff-prep
"$1" "$f1"
483 _cdiff-prep
"$2" "$f2"
484 cat "$f1" "$f2" |
grep -Po '^[^=]+=' |
sort |
uniq > "$unified"
485 while IFS
= read -r line
; do
486 # the default bright red / blue doesnt work in emacs shell
487 dwdiff
-cblue,red
-A best
-d " ," <(grep "^$line" "$f1" ||
echo ) <(grep "^$line" "$f2" ||
echo ) | colordiff
494 cp /a
/bin
/data
/COPYING
"$@"
496 cp /a
/bin
/data
/COPYING .
503 cp /a
/bin
/data
/LICENSE
"$@"
505 cp /a
/bin
/data
/LICENSE .
512 inotifywait
-m "$dir" -e create
-e moved_to |
513 while read filedir _
file; do
516 calc $
((SECONDS
- start
)) / 60
523 # makes it so chown -R symlink affects the symlink and its target.
524 if [[ $1 == -R ]]; then
526 command chown
-h "$@"
527 command chown
-R "$@"
538 # choose recent directory. cl = cd list
543 if type -p chromium
&>/dev
/null
; then
547 cmd
="schroot -c stretch chromium"
548 CHROMIUM_FLAGS
='--enable-remote-extensions' $cmd &r
553 complete
-A stopped
-P '"%' -S '"' d
555 dat
() { # do all tee, for more complex scripts
556 tee >(ssh frodo bash
-l) >(bash
-l) >(ssh x2 bash
-l) >(ssh tp bash
-l)
561 for host in x2 tp kd
; do
567 diff --strip-trailing-cr -w "$@" # diff content
570 debian_pick_mirror
() {
571 # netselect-apt finds a fast mirror.
572 # but we need to replace the mirrors ourselves,
573 # because it doesnt do that. best it can do is
574 # output a basic sources file
575 # here we get the server it found, get the main server we use
576 # then substitute all instances of one for the other in the sources file
577 # and backup original to /etc/apt/sources.list-original.
578 # this is idempotent. the only way to identify debian sources is to
579 # note the original server, so we put it in a comment so we can
581 local file=$
(mktemp
-d)/f
# safe way to get file name without creating one
582 sudo netselect-apt
-o "$file" ||
return 1
583 url
=$
(grep ^
\\w
$file |
head -n1 |
awk '{print $2}')
584 sudo
cp -f /etc
/apt
/sources.list
/etc
/apt
/sources.list-original
585 sudo
sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc
/apt
/sources.list
593 safe_rename
"$x" "$y"
598 date "+%A, %B %d, %r" "$@"
601 dus
() { # du, sorted, default arg of
602 du
-sh ${@:-*} |
sort -h
611 [[ ${#@} == 2 ]] ||
{ echo "error: ediff requires 2 arguments"; return 1; }
612 emacs
--eval "(ediff-files \"$1\" \"$2\")"
616 envload
() { # load environment from a previous: export > file
617 local file=${1:-$HOME/.${USER}_env}
618 eval "$(export | sed 's/^declare -x/export -n/')"
619 while IFS
= read -r line
; do
620 # declare -x makes variables local to a function
621 eval ${line/#declare -x/export}
627 sudo
tail -F /var
/log
/exim
4/mainlog
-n 50
636 # find array. make an array of file names found by find into $x
637 # argument: find arguments
638 # return: find results in an array $x
639 while read -rd ''; do
641 done < <(find "$@" -print0);
644 faf
() { # find all files
645 find -L $1 -type f
-not \
( -name .svn
-prune -o -name .git
-prune \
646 -o -name .hg
-prune -o -name .editor-backups
-prune \
647 -o -name .undo-tree-history
-prune \
) 2>/dev
/null
650 # one that comes with distros is too old for newer devices
652 /a
/opt
/android-platform-tools
/fastboot
"$@";
655 kdecd
() { /usr
/lib
/x86_64-linux-gnu
/libexec
/kdeconnectd
; }
657 # List of apps to install/update
658 # Create from existing manually installed apps by doing
660 # fdroidcl search -i, then manually removing
661 # automatically installed/preinstalled apps
664 # # my attempt at recovering from boot loop:
665 # # in that case, boot to recovery (volume up, home button, power, let go of power after samsun logo)
667 # mount /dev/block/mmcblk0p12 /data
669 # find -iname '*appname*'
671 # usually good enough to just rm -rf /data/app/APPNAME
674 # # causes replicant to crash
675 # org.quantumbadger.redreader
676 # org.kde.kdeconnect_tp
678 # not broke, but wont work without gps
679 #com.zoffcc.applications.zanavi
680 # not broke, but not using atm
681 #com.nutomic.syncthingandroid
682 # # doesn\'t work on replicant
683 #net.sourceforge.opencamera
686 de.marmaro.krt.ffupdater
687 me.ccrama.redditslide
688 org.fedorahosted.freeotp
690 com.alaskalinuxuser.justnotes
691 com.artifex.mupdf.viewer.app
692 com.danielkim.soundrecorder
694 com.ghostsq.commander
696 com.jmstudios.redmoon
698 org.kde.kdeconnect_tp
701 cz.martykan.forecastie
704 de.marmaro.krt.ffupdater
705 eu.siacs.conversations
707 im.vector.alpha
# riot
709 me.tripsit.tripmobile
711 net.minetest.minetest
716 org.smssecure.smssecure
718 sh.
ftp.rocketninelabs.meditationassistant.opensource
720 # https://forum.xda-developers.com/android/software-hacking/wip-selinux-capable-superuser-t3216394
725 local -A installed updated
728 if fdroidcl search
-u |
grep ^org.fdroid.fdroid
; then
729 fdroidcl upgrade org.fdroid.fdroid
733 for p
in $
(fdroidcl search
-i|
grep -o "^\S\+"); do
736 for p
in $
(fdroidcl search
-u|
grep -o "^\S\+"); do
739 for p
in ${fdroid_pkgs[@]}; do
740 if ! ${installed[$p]:-false}; then
742 # sleeps are just me being paranoid since replicant has a history of crashing when certain apps are installed
746 for p
in ${!installed[@]}; do
747 if ! ${updated[$p]:-true}; then
754 firefox-default-profile
() {
755 key
=Default value
=1 section
=$1
756 file=/p
/c
/subdir_files
/.mozilla
/firefox
/profiles.ini
757 sed -ri "/^ *$key/d" "$file"
758 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d};/ *\[$section\]/a $key=$value" "$file"
760 fdhome
() { #firefox default home profile
761 firefox-default-profile Profile0
765 firefox-default-profile Profile4
769 if type -P firefox
&>/dev
/null
; then
779 firefox
-P alt
"$@" >/dev
/null
2>&1
785 local dname
="${PWD##*/}"
786 local m
="/a/tmp/$dname-missing"
787 local d
="/a/tmp/$dname-diff"
788 [[ -e $d ]] && rm "$d"
789 [[ -e $m ]] && rm "$m"
792 while read -r line
; do
794 if [[ -e "$fsfile" ]]; then
795 md5diff
"$line" "$fsfile" && tee -a "/a/tmp/$dname-diff" <<< "$fsfile $line"
801 done < <(find -type f
)
804 (( msize
<= 100 )) && cat $m
808 # expected output, with different tmp dirs
809 # /tmp/tmp.HDPbwMqdC9/c/d ./c/d
810 # /a/tmp/tmp.qLDkYxBYPM-missing
819 echo different
> $x/c
/d
824 # test whether missing files were renamed, generally for use with fsdiff
825 # $1 = fsdiff output file, $2 = directory to compare to. pwd = fsdiff dir
826 # echos non-renamed files
830 { sums
+=( "$(md5sum < "$x")" ) ; } 2>/dev
/null
832 while read -r line
; do
833 { missing_sum
=$
(md5sum < "$line") ; } 2>/dev
/null
835 for x
in "${sums[@]}"; do
836 if [[ $missing_sum == "$x" ]]; then
841 $renamed ||
echo "$line"
847 # F = fullscren, z = random, Z = auto zoom
848 command feh
-FzZ "$@"
854 s mailq |gr frozen|
awk '{print $3}' |
while read -r id
; do
860 echo -e '\n\n##############################\n'
861 done |
tee -a /tmp
/frozen
865 while read -r line
; do
866 printf '%s\n' "$line"
867 ids
+=($
(printf '%s\n' "$line" |gr frozen|
awk '{print $3}'))
869 echo "sleeping for 2 in case you change your mind"
871 s exim
-Mrm "${ids[@]}"
875 # like -e for functions. returns on error.
876 # at the end of the function, disable with:
878 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
879 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"
886 firefox
-P default
"$@" >/dev
/null
2>&1
890 local help="Usage: getdir [--help] PATH
891 Output the directory of PATH, or just PATH if it is a directory."
892 if [[ $1 == --help ]]; then
896 if [[ $# -ne 1 ]]; then
897 echo "getdir error: expected 1 argument, got $#"
903 local dir
="$(dirname "$1")"
904 if [[ -d $dir ]]; then
907 echo "getdir error: directory does not exist"
913 git_empty_branch
() { # start an empty git branch. carefull, it deletes untracked files.
914 [[ $# == 1 ]] ||
{ echo 'need a branch name!'; return 1;}
916 gitroot ||
return 1 # function to set gitroot
917 builtin cd "$gitroot"
918 git symbolic-ref HEAD refs
/heads
/$1
924 local help="Usage: gitroot [--help]
925 Print the full path to the root of the current git repo
927 Handles being within a .git directory, unlike git rev-parse --show-toplevel,
928 and works in older versions of git which did not have that."
929 if [[ $1 == --help ]]; then
933 local p
=$
(git rev-parse
--git-dir) ||
{ echo "error: not in a git repo" ; return 1; }
934 [[ $p != /* ]] && p
=$PWD
939 git config user.email ian@iankelling.org
943 # i got an error, gh not found when doing a pull request, it seems like it wants itself in it\'s path.
944 local _oldpath
="$PATH"
945 PATH
="$PATH:~/node_modules/.bin"
951 # quit will prompt if the program crashes.
952 gdb
-ex=r
-ex=quit
--args emacs
"$@"; r
;
956 # kill the emacs daemon
960 # at least in flidas, things rely on gpg being gpg1
966 local email
=ian@iankelling.org
967 if readlink ~
/.mu |
grep fsf
&>/dev
/null
; then
970 git send-email
--notes "--envelope-sender=<$email>" \
971 --suppress-cc=self
"$@"
975 grep -iIP --color=auto
"$@"
978 grr
() { # grep recursive
979 if [[ ${#@} == 1 ]]; then
980 grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto
"$@" .
982 grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -RiIP --color=auto
"$@"
987 # do git status on published repos
991 cd `readlink -f $x`/..
992 status
=$
(i status
-s) ||
pwd
993 if [[ $status ]]; then
996 printf "%s\n" "$status"
1002 hl
() { # history limit. Write extra history to archive file.
1003 # todo: this is not working or not used currently
1004 local max_lines linecount tempfile prune_lines x
1005 local harchive
="${HISTFILE}_archive"
1006 for x
in "$HISTFILE" "$harchive"; do
1007 [[ -e $x ]] ||
{ touch "$x" && echo "notice from hl(): creating $x"; }
1008 if [[ ! $x ||
! -e $x ||
! -w $x || $
(stat
-c "%u" "$x") != $EUID ]]; then
1009 echo "error in hl: history file \$x:$x no good"
1013 history -a # save history
1014 max_lines
=$HISTFILELINES
1015 [[ $max_lines =~ ^
[0-9]+$
]] ||
{ echo "error in hl: failed to get max line count"; return 1; }
1016 linecount
=$
(wc -l < $HISTFILE) # pipe so it doesnt output a filename
1017 [[ $linecount =~ ^
[0-9]+$
]] ||
{ echo "error in hl: wc failed"; return 1; }
1018 if (($linecount > $max_lines)); then
1019 prune_lines
=$
(($linecount - $max_lines))
1020 head -n $prune_lines "$HISTFILE" >> "$harchive" \
1021 && sed --follow-symlinks -ie "1,${prune_lines}d" $HISTFILE
1025 hr
() { # horizontal row. used to break up output
1026 printf "$(tput setaf 5)â–ˆ$(tput sgr0)%.0s" $
(seq ${COLUMNS:-60})
1030 hrcat
() { local f
; for f
; do [[ -f $f ]] ||
continue; hr
; echo "$f"; cat "$f"; done }
1032 # get latest hub and run it
1033 # main command to use:
1034 # hub pull-request --no-edit
1035 # --no-edit means to use the first commit\'s message as the pull request message.
1036 # Also, you need to use a feature branch, not master in your fork.
1037 # On first use, you input username/pass and it gets an oath token so you dont have to repeat
1038 # it\'s at ~/.config/hub
1040 local up uptar updir p
1041 p
=/github
/hub
/releases
/
1042 up
=https
://github.com
/$
(curl
-s https
://github.com
$p|
grep -o $p'download/[^/]*/hub-linux-amd64[^"]*' |
head -n1)
1045 if [[ ! -e /a
/opt
/$updir ]]; then
1046 rm -rf /a
/opt
/hub-linux-amd64
*
1048 tar -C /a
/opt
-zxf /a
/opt
/$uptar
1050 s
/a
/opt
/$updir/install
1053 # save token across computers
1054 if [[ ! -L ~
/.config
/hub
]]; then
1055 if [[ -e ~
/.config
/hub
]]; then
1056 mv ~
/.config
/hub
/p
/c
/subdir_files
/.config
/
1058 if [[ -e /p
/c
/subdir_files
/.config
/hub
]]; then
1066 # modified from ~/local/bin/git-completion.bash
1067 # other completion commands are mostly taken from bash_completion package
1068 complete
-o bashdefault
-o default
-o nospace
-F _git i
2>/dev
/null \
1069 || complete
-o default
-o nospace
-F _git i
1071 if ! type service
&>/dev
/null
; then
1073 echo actually running
: systemctl
$2 $1
1085 /a
/opt
/idea-IC-163.7743
.44/bin
/idea.sh
"$@" &r
1090 find -L .
-not \
( -name .svn
-prune -o -name .git
-prune \
1091 -o -name .hg
-prune -o -name .editor-backups
-prune \
1092 -o -name .undo-tree-history
-prune \
) -iname "*$**" 2>/dev
/null
1096 if [[ $OS == Windows_NT
]]; then
1107 (( ${#x[#]} > 1 )) && { echo "warning ${#x[#]} matches found"; sleep 1; }
1112 if type gvfs-open
&> /dev
/null
; then
1117 # another alternative is run-mailcap
1122 s iptables
-A INPUT
-s $1 -j DROP
1127 grep -Il "" "$@" &>/dev
/null
1131 grep -Evi -e "^(\S+\s+){4}(sudo|sshd|cron)\[\S*:" \
1132 -e "^(\S+\s+){4}systemd\[\S*: (starting|started) (btrfsmaintstop|dynamicipupdate|spamd dns bug fix cronjob|rss2email)\.*$"
1135 journalctl
-n 10000 -f "$@" | jfilter
1137 jr
() { journalctl
"$@" | jfilter |
less ; }
1138 jrf
() { journalctl
-f "$@" | jfilter
; }
1140 kff
() { # keyboardio firmware flash
1141 pushd /a
/bin
/distro-setup
/Arduino
/Model01-Firmware
1142 yes $
'\n' |
make flash
1147 if [[ $PWD == /[iap
] ]]; then
1148 command ls -A --color=auto
-I lost
+found
"$@"
1150 command ls -A --color=auto
"$@"
1155 lcn
() { locate -i "*$**"; }
1157 lg
() { LC_COLLATE
=C.UTF-8 ll
--group-directories-first; }
1159 lt
() { ll
-tr "$@"; }
1161 lld
() { ll
-d "$@"; }
1165 if [[ $1 == /* ]]; then
1167 if mountpoint
/mnt
/$base; then
1170 l
=$
(sudo losetup
-f)
1172 if ! sudo cryptsetup luksOpen
$l $base; then
1176 sudo mkdir
-p /mnt
/$base
1177 sudo mount
/dev
/mapper
/$base /mnt
/$base
1178 sudo chown
$USER:$USER /mnt
/$base
1181 sudo umount
/mnt
/$base
1182 l
=$
(sudo cryptsetup status
/dev
/mapper
/$base|
sed -rn 's/^\s*device:\s*(.*)/\1/p')
1183 sudo cryptsetup luksClose
/dev
/mapper
/$base ||
return 1
1188 low
() { # make filenames lowercase, remove bad chars
1191 new
="${f,,}" # downcase
1192 new
="${new//[^[:alnum:]._-]/_}" # sub bad chars
1193 new
="${new#"${new%%[[:alnum:]]*}"}" # remove leading/trailing non-alnum
1194 new
="${new%"${new##*[[:alnum:]]}"}"
1195 # remove bad underscores, like __ and _._
1196 new
=$
(echo $new |
sed -r 's/__+/_/g;s/_+([.-])|([.-])_+/\1/g')
1197 safe_rename
"$f" "$new" ||
return 1
1202 lower
() { # make first letter of filenames lowercase.
1205 if [[ ${x::1} == [A-Z
] ]]; then
1206 y
=$
(tr "[A-Z]" "[a-z]" <<<"${x::1}")"${x:1}"
1207 safe_rename
"$x" "$y" ||
return 1
1213 k
() { # history search
1214 grep -P --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
tail -n 80;
1217 ks
() { # history search
1218 grep -P --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
uniq;
1223 # show make targets, via http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make
1224 make -qp |
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
1232 [[ -e $src ]] ||
{ set +x
; return 1; }
1233 mv -T $src $dst ||
{ set +x
; return 1; }
1236 mu index
--maildir=/m
/4e
1244 [[ -e $src ]] ||
{ set +x
; return 1; }
1245 if [[ -L $dst ]]; then rm $dst; fi
1252 markdown
"$1" >/tmp
/mdtest.html
1253 firefox
/tmp
/mdtest.html
1266 mkt
() { # mkdir and touch file
1268 mkdir
-p "$(dirname "$path")"
1272 mkdir
() { command mkdir
-p "$@"; }
1274 mo
() { xset dpms force off
; } # monitor off
1277 e
"lspci -nnk|gr -iA2 net"
1278 lspci
-nnk|gr
-iA2 net
1280 e
"s lshw -C network"
1287 sudo
tee -a /var
/log
/exim
4/paniclog-archive
</var
/log
/exim
4/paniclog
; sudo truncate
-s0 /var
/log
/exim
4/paniclog
1292 oathtool
--totp -b "$@" | xclip
-selection clipboard
1295 p8
() { ping 8.8.8.8; }
1298 # from http://askubuntu.com/questions/456021/remove-vocals-from-mp3-and-get-only-instrumentals
1299 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
1303 pfind
() { #find *$1* in $PATH
1304 [[ $# != 1 ]] && { echo requires
1 argument
; return 1; }
1306 IFS
=: pathArray
=($PATH); unset IFS
1307 find "${pathArray[@]}" -iname "*$1*"
1310 pkx
() { # package extract
1313 cached
=$
(ls -t /var
/cache
/apt
/archives
/$pkg* |
tail -n1)
1314 if [[ $cached ]]; then
1317 aptitude download
$pkg
1326 pid
=($
(pgrep
-f "$*"))
1332 0) echo "no pid found" ;;
1340 # trash-restore lists everything that has been trashed at or below CWD
1341 # This picks out files just in CWD, not subdirectories,
1342 # which also match grep $1, usually use $1 for a time string
1343 # which you get from running restore-trash once first
1346 # last condition is to not ask again for ones we skipped
1347 while name
="$( echo | restore-trash | gr "$PWD/[^
/]\
+$
" | gr "$1" )" \
1348 && [[ $name ]] && (( $
(wc -l <<<"$name") >= nth
)); do
1349 name
="$(echo "$name" | head -n $nth | tail -n 1 )"
1350 read -p "$name [Y/n] " ask
1351 if [[ ! $ask ||
$ask == [Yy
] ]]; then
1352 x
=$
( echo "$name" | gr
-o "^\s*[0-9]*" )
1353 echo $x | restore-trash
> /dev
/null
1354 elif [[ $ask == [Nn
] ]]; then
1364 rld
/a
/h
/_site
/ li
:/var
/www
/iankelling.org
/html
1367 pubip
() { curl
-4s https
://icanhazip.com
; }
1368 pubip6
() { curl
-6s https
://icanhazip.com
; }
1369 whatismyip
() { pubip
; }
1372 # fixes the menu bar in xmonad. this won\'t be needed when xmonad
1373 # packages catches up on some changes in future (this is written in
1376 # geekosaur: so youll want to upgrade to xmonad 0.13 or else use a
1377 # locally modified XMonad.Hooks.ManageDocks that doesnt set the
1378 # work area; turns out it\'s impossible to set correctly if you are
1379 # not a fully EWMH compliant desktop environment
1381 # geekosaur: chrome shows one failure mode, qt/kde another, other
1382 # gtk apps a third, ... I came up with a setting that works for me
1383 # locally but apparently doesnt work for others, so we joined the
1384 # other tiling window managers in giving up on setting it at all
1386 xprop
-root -remove _NET_WORKAREA
1394 # -t = print pronunciation
1396 for (( i
=0; i
<10; i
++ )); do
1397 shuf
-n3 /usr
/share
/hunspell
/en_US.dic |
sed 's,/.*,,' |
paste -sd .
-
1403 # -M CLN = use Caps, Lowercase, Numbers
1405 # -a 1 = use random instead of pronounceable algorithm
1406 apg
-m 50 -x 70 -n 1 -a 1 -M CLN
1410 q
() { # start / launch a program in the backround and redir output to null
1415 exit "$@" 2>/dev
/null
1418 rbpipe
() { rbt post
-o --diff-filename=- "$@"; }
1419 rbp
() { rbt post
-o "$@"; }
1425 hr
; echo dnsmasq is $
(systemctl is-active dnsmasq
)
1426 f
=/var
/run
/dnsmasq
/resolv.conf
1427 hr
; echo $f:; ccat
$f
1428 f
=/etc
/dnsmasq-servers.conf
1429 hr
; echo $f:; ccat
$f
1433 # rsync, root is required to keep permissions right.
1434 # rsync --archive --human-readable --verbose --itemize-changes --checksum \(-ahvic\) \
1435 # --no-times --delete
1436 # basically, make an exact copy, use checksums instead of file times to be more accurate
1437 rsync
-ahvic --delete "$@"
1440 # like rlu, but dont delete files on the target end which
1441 # do not exist on the original end.
1444 complete
-F _rsync
-o nospace rld rl rlt
1447 # rl without preserving modification time.
1448 rsync
-ahvic --delete --no-t "$@"
1451 rlu
() { # [OPTS] HOST PATH
1452 # eg. rlu -opts frodo /testpath
1453 # relative paths will expanded with readlink -f.
1454 # useful for selectively sending dirs which have been synced with unison,
1455 # where the path is the same on both hosts.
1456 opts
=("${@:1:$#-2}") # 1 to last -2
1457 path
="${@:$#}" # last
1458 host="${@:$#-1:1}" # last -1
1459 if [[ $path == .
* ]]; then
1460 path
=$
(readlink
-f $path)
1462 # rync here uses checksum instead of time so we dont mess with
1463 # unison relying on time as much. g is for group, same reason
1464 # to keep up with unison.
1465 s rsync
-rlpchviog --relative "${opts[@]}" "$path" "root@$host:/";
1468 # only run on MAIL_HOST. simpler to keep this on one system.
1469 r2eadd
() { # usage: name url
1470 # initial setup of rss2email:
1471 # r2e new r2e@iankelling.org
1472 # that initializes files, and sets default email.
1473 # symlink to the config doesnt work, so I copied it to /p/c
1474 # and then use cli option to specify explicit path.
1475 # Only option changed from default config is to set
1478 # or else for a few feeds, the from address is set by the feed, and
1479 # if I fail delivery, then I send a bounce message to that from
1480 # address, which makes me be a spammer.
1482 r2e add
$1 "$2" $1@r2e.iankelling.org
1483 # get up to date and dont send old entries now:
1484 r2e run
--no-send $1
1486 r2e
() { command r2e
-d /p
/c
/rss2email.json
-c /p
/c
/rss2email.cfg
"$@"; }
1488 rspicy
() { # usage: HOST DOMAIN
1489 # connect to spice vm remote host. use vspicy for local host
1490 local port
=$
(ssh $1<<EOF
1491 sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
1492 sed -rn "s/.*port='([0-9]+).*/\1/p"
1495 if [[ $port ]]; then
1496 spicy
-h $1 -p $port
1498 echo "error: no port found. check that the domain is running."
1503 ssh fencepost
head -n 300 /gd
/gnuorg
/EventAndTravelInfo
/rms-current-trips.txt |
less
1508 # I use a function because otherwise we cant use in a script,
1509 # cant assign to variable.
1511 # note: gksudo is recommended for X apps because it does not set the
1512 # home directory to the same, and thus apps writing to ~ fuck things up
1513 # with root owned files.
1515 if [[ $EUID != 0 ||
$1 == -* ]]; then
1516 SUDOD
="$PWD" sudo
-i "$@"
1522 safe_rename
() { # warn and dont rename if file exists.
1523 # mv -n exists, but it\'s silent
1524 if [[ $# != 2 ]]; then
1525 echo safe_rename error
: $# args
, need
2 >2
1528 if [[ $1 != $2 ]]; then # yes, we want to silently ignore this
1529 if [[ -e $2 ||
-L $2 ]]; then
1530 echo "Cannot rename $1 to $2 as it already exists."
1538 sb
() { # sudo bash -c
1539 # use sb instead of s is for sudo redirections,
1540 # eg. sb 'echo "ok fine" > /etc/file'
1542 sudo
-i bash
-c "$@"
1544 complete
-F _root_command s sb
1547 # s gem install scss-lint
1548 pushd /a
/opt
/thoughtbot-guides
1551 scss-lint
-c /a
/opt
/thoughtbot-guides
/style
/sass
/.scss-lint.yml
"$@"
1555 local s
; [[ $EUID != 0 ]] && s
=s
1556 if type -p systemctl
&>/dev
/null
; then
1562 # like restart, but do nothing if its not already started
1565 if [[ $
(s systemctl
--no-pager show
-p ActiveState
$service ) == ActiveState
=active
]]; then
1566 systemctl restart
$service
1570 ser stop NetworkManager
1572 s resolvconf
-d NetworkManager
1576 ser start NetworkManager
1580 setini
() { # set a value in a .ini style file
1581 key
="$1" value
="$2" section
="$3" file="$4"
1582 if [[ -s $file ]]; then
1583 sed -ri -f - "$file" <<EOF
1584 # remove existing keys
1585 / *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d}
1587 /^\s*\[$section\]/a $key=$value
1588 # from section to eof, do nothing
1589 /^\s*\[$section\]/,\$b
1590 # on the last line, if we haven't found section yet, add section and key
1602 sgo
() { # service go
1604 ser restart
$service ||
return 1
1605 if type -p systemctl
&>/dev
/null
; then
1612 # 2086 = unquoted $var
1613 # 2046 = unquoted $(cmd)
1614 # i had -x as an arg, but debian testing(stretch) doesn\'t support it
1615 shellcheck
-e 2086,2046,2068,2006,2119 "$@"
1621 out
=${2:-${1%.*}.sh}
1623 script -t -c "mpv --no-config --no-resume-playback --no-terminal --no-audio-display '$1'" $tmp/typescript
2>$tmp/timing
1624 # todo, the current sleep seems pretty good, but it
1625 # would be nice to have an empirical measurement, or
1626 # some better wait to sync up.
1628 # note: --loop-file=no prevents it from hanging if you have that
1629 # set to inf the mpv config.
1630 # --loop=no prevents it from exit code 3 due to stdin if you
1631 # had it set to inf in mpv config.
1633 # args go to mpv, for example --volume=80, 50%
1634 cat >$out <<EOFOUTER
1636 trap "trap - TERM && kill 0" INT TERM ERR; set -e
1637 ( sleep .2; scriptreplay <( cat <<'EOF'
1641 $(cat $tmp/typescript)
1644 base64 -d - <<'EOF'| mpv --loop=no --loop-file=no --no-terminal --no-audio-display "\$@" -
1654 # log with script. timing is $1.t and script is $1.s
1655 # -l to save to ~/typescripts/
1656 # -t to add a timestamp to the filenames
1657 local logdir do_stamp arg_base
1658 (( $# >= 1 )) ||
{ echo "arguments wrong"; return 1; }
1661 while getopts "lt" option
1664 l
) arg_base
=$logdir ;;
1665 t
) do_stamp
=true
;;
1668 shift $
(($OPTIND - 1))
1670 [[ -e $logdir ]] || mkdir
-p $logdir
1671 $do_stamp && arg_base
+=$
(date +%F.
%T
%z
)
1672 script -t $arg_base.s
2> $arg_base.t
1674 splay
() { # script replay
1675 #logRoot="$HOME/typescripts/"
1676 #scriptreplay "$logRoot$1.t" "$logRoot$1.s"
1677 scriptreplay
"$1.t" "$1.s"
1680 smeld
() { # ssh meld usage host1 host2 file
1681 meld
<(ssh $1 cat $3) <(ssh $2 cat $3)
1685 PATH
=/usr
/local
/spdhackfix
:$PATH command spd
"$@"
1693 # sudo redo. be aware, this command may not work right on strange distros or earlier software
1694 if [[ $# == 0 ]]; then
1695 sudo
-E bash
-c -l "$(history -p '!!')"
1697 echo this
command redos last
history item. no argument is accepted
1702 # with -ll, less secure but faster.
1703 command srm
-ll "$@"
1708 ssh $1 /tmp
/${2##*/} "${@:2}"
1712 ssh -oControlMaster=no
-oControlPath=/ "$@"
1716 while [[ $1 == -* ]]; do
1720 m pkill
-f "^ssh: /tmp/ssh_mux_${USER}_${1#*@}_22_"
1721 m
ssh "${opts[@]}" "$@"
1735 if type -t trash-put
>/dev
/null
; then
1736 # skip args that dont exist, or else trash-put will have an error
1738 if [[ -e $x ||
-L $x ]]; then
1742 [[ ! ${args[@]} ]] || trash-put
"${args[@]}"
1753 # this goes to full width
1754 #len=${1:-$((COLUMNS -7))}
1757 if (( x
== len
)); then
1759 d
="$(date +%l:%_M) "
1762 d
=$
(date +%l
:%M
:%_S
)
1766 for ((i
=0; i
<x
; i
++)); do
1767 if (( i
% 6 )); then
1785 # test existence / exists
1788 [[ -e "$x" ||
-L "$x" ]] || ret
=1
1795 declare -gi _seq
; _seq
+=1
1796 echo "test body" | m
mail -s "test mail from $HOSTNAME, $_seq" "${@:-root@localhost}"
1797 # for testing to send from an external address, you can do for example
1798 # -fian@iank.bid -aFrom:ian@iank.bid web-6fnbs@mail-tester.com
1799 # note in exim, you can retry a deferred message
1801 # MSG_ID is in /var/log/exim4/mainlog, looks like 1ccdnD-0001nh-EN
1804 # to test sieve, use below command. for fsf mail, see fsf-get-mail script.
1805 # make modifications, then copy to live file, use -eW to actually modify mailbox
1806 # cp /p/c/subdir_files/sieve/personal{test,}.sieve; testsievelist -eW INBOX
1808 # Another option is to use sieve-test SCRIPT MAIL_FILE. note,
1809 # sieve-test doesnt know about envelopes, Im not sure if sieve-filter does.
1811 # sieve with output filter. arg is mailbox, like INBOX.
1812 # This depends on dovecot conf, notably mail_location in /etc/dovecot/conf.d/10-mail.conf
1815 sieve-filter ~
/sieve
/maintest.sieve
"$@" >/tmp
/testsieve.log
2> >(tail) && sed -rn '/^Performed actions:/{n;n;p}' /tmp
/testsieve.log |
sort -u
1822 sieve-filter ~
/sieve
/main.sieve
"$@"
1827 # testmail above calls sendmail, which is a link to exim/postfix.
1828 # its docs dont say a way of adding an argument
1829 # to sendmail to turn on debug output. We could make a wrapper, but
1830 # that is a pain. Exim debug args are documented here:
1831 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
1833 # http://www.exim.org/exim-html-current/doc/html/spec_html/ch-building_and_installing_exim.html
1834 # note, for exim daemon, you can turn on debug options by
1835 # adding -d, etc to COMMONOPTIONS in
1836 # /etc/default/exim4
1838 From: ian@iankelling.org
1839 To: root@lists0p.fsf.org
1840 Subject: Testing Exim
1842 This is a test message.
1849 # https://askubuntu.com/questions/160945/is-there-a-way-to-disable-a-laptops-internal-keyboard
1850 id
=$
(xinput
--list --id-only 'AT Translated Set 2 keyboard')
1851 if xinput list |
grep -F '∼ AT Translated Set 2 keyboard' &>/dev
/null
; then
1852 echo enabling keyboard
1853 # find the first slave keyboard number, they are all the same in my output.
1854 # if they werent, worst case we would need to save the slave number somewhere
1855 # when it got disabled.
1856 slave
=$
(xinput list |
sed -n 's/.*slave \+keyboard (\([0-9]*\)).*/\1/p' |
head -n1)
1857 xinput reattach
$id $slave
1866 (sleep $
(calc
"$@ * 60") && mpv
--no-config --volume 50 /a
/bin
/data
/alarm.mp3
) > /dev
/null
2>&1 &
1869 trg
() { transmission-remote-gtk
&r
; }
1871 # example, set global upload limit to 100 kilobytes:
1873 TR_AUTH
=":$(jq -r .profiles[0].password ~/.config/transmission-remote-gtk/config.json)" transmission-remote transmission.lan
-ne "$@"
1879 local dir
="$(dirname "$1")"
1880 if [[ -e $1 && ! -w $1 ||
! -w $
(dirname "$1") ]]; then
1886 tx
() { # toggle set -x, and the prompt so it doesnt spam
1887 if [[ $
- == *x
* ]]; then
1889 PROMPT_COMMAND
=prompt-command
1890 # disabled due to issue on stretch, running ll we get error. something
1891 # about the DEBUG trap is broken
1892 # if [[ $TERM == *(screen*|xterm*|rxvt*) ]]; then
1893 # trap 'settitle "$BASH_COMMAND"' DEBUG
1896 # normally, i would just execute these commands in the function.
1897 # however, DEBUG is not inherited, so we need to run it outside a function.
1898 # And we want to run set -x afterwards to avoid spam, so we cram everything
1899 # in here, and then it will run after this function is done.
1900 #PROMPT_COMMAND='trap DEBUG; unset PROMPT_COMMAND; PS1="\w \$ "; set -x'
1902 unset PROMPT_COMMAND
1909 # show all processes in the network namespace $1.
1910 # blank entries appear to be subprocesses/threads
1914 s
find -L /proc
/[1-9]*/task
/*/ns
/net
-samefile /run
/netns
/$netns | cut
-d/ -f5 | \
1916 x
=$
(ps
-w --no-headers -p $l);
1917 if [[ $x ]]; then echo "$x"; else echo $l; fi;
1921 m
() { printf "%s\n" "$*"; "$@"; }
1925 #m s nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*pia.conf") -n -m "$@"
1926 m s nsenter
-t $
(pgrep
-f "/usr/sbin/openvpn .* --config /etc/openvpn/.*client.conf") -n -m "$@"
1929 vpncmd gksudo
-u iank
"firefox -no-remote -P vpn" &r
1932 vpncmd gksudo
-u iank
"$*"
1941 for x
in "$@"; do virsh destroy
"$x"; virsh undefine
"$x"; done
1948 s virsh dumpxml
$vm |
sed -r "s/(<listen.*address=')([^']+)/\1$ip/" | \
1949 sed -r "s/listen='[^']+/listen='$ip/"> $t
1950 s virsh undefine
$vm
1956 vm-set-listen
$1 0.0.0.0
1961 vm-set-listen
$1 127.0.0.1
1966 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
1967 local vpn_service
=openvpn-client
1969 local vpn_service
=openvpn
1972 [[ $1 ]] ||
{ echo need arg
; return 1; }
1973 journalctl
--unit=$vpn_service@
$1 -f -n0 &
1974 s systemctl start
$vpn_service@
$1
1975 # sometimes the ask-password agent does not work and needs a delay.
1977 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779240
1978 # noticed around 8-2017 after update from around stretch release
1979 # on debian testing, even though the bug is much older.
1980 s systemd-tty-ask-password-agent
1984 [[ $1 ]] ||
{ echo need arg
; return 1; }
1985 if [[ -e /lib
/systemd
/system
/openvpn-client@.service
]]; then
1986 local vpn_service
=openvpn-client
1988 local vpn_service
=openvpn
1990 s systemctl stop
$vpn_service@
$1
2001 vspicy
() { # usage: VIRSH_DOMAIN
2002 # connect to vms made with virt-install
2003 spicy
-p $
(sudo virsh dumpxml
"$1"|
grep "<graphics.*type='spice'"|\
2004 sed -r "s/.*port='([0-9]+).*/\1/")
2008 cat-new-files
/m
/4e
/INBOX
/new
2011 wtr
() { curl wttr.in
/boston
; }
2014 if pgrep gnome-screensav
&>/dev
/null
; then
2015 # this command actually starts gnome-screensaver if it isn\'t running.
2016 # lololol, what crap
2017 gnome-screensaver-command
--exit &>/dev
/null
2019 mate-screensaver-command
--exit &>/dev
/null
2020 if ! pidof xscreensaver
; then
2024 # 1 was not long enough
2027 xscreensaver-command
-activate
2030 xevkb
() { xev
-event keyboard
; }
2034 # from curl cheat.sh/:bash_completion
2035 _cheatsh_complete_curl
()
2038 _get_comp_words_by_ref
-n : cur
2041 #cur="${COMP_WORDS[COMP_CWORD]}"
2042 prev
="${COMP_WORDS[COMP_CWORD-1]}"
2043 opts
="$(curl -s cheat.sh/:list | sed s@^@cheat.sh/@)"
2045 if [[ ${cur} == cheat.sh
/* ]] ; then
2046 COMPREPLY
=( $
(compgen
-W "${opts}" -- ${cur}) )
2047 __ltrim_colon_completions
"$cur"
2051 complete
-F _cheatsh_complete_curl curl
2054 if [[ $
- == *i
* ]]; then
2055 # commands to run when bash exits normally
2060 # temporary variables to test colorization
2061 # some copied from gentoo /etc/bash/bashrc,
2063 # dircolors --print-database uses its own built-in database
2064 # instead of using /etc/DIR_COLORS. Try to use the external file
2065 # first to take advantage of user additions.
2066 safe_term
=${TERM//[^[:alnum:]]/?} # sanitize TERM
2068 [[ -f ~
/.dir_colors
]] && match_lhs
="${match_lhs}$(<~/.dir_colors)"
2069 [[ -f /etc
/DIR_COLORS
]] && match_lhs
="${match_lhs}$(</etc/DIR_COLORS)"
2070 [[ -z ${match_lhs} ]] \
2071 && type -P dircolors
>/dev
/null \
2072 && match_lhs
=$
(dircolors
--print-database)
2073 # test if our $TERM is in the TERM values in dircolor
2074 [[ $
'\n'${match_lhs} == *$
'\n'"TERM "${safe_term}* ]] && use_color
=true
2077 if ${use_color} && [[ $
- == *i
* ]]; then
2079 if [[ $XTERM_VERSION == Cygwin
* ]]; then
2083 underl
) echo -n $
'\E[4m' ;;
2084 bold
) echo -n $
'\E[1m' ;;
2085 red
) echo -n $
'\E[31m' ;;
2086 green
) echo -n $
'\E[32m' ;;
2087 blue
) echo -n $
'\E[34m' ;;
2088 cyan
) echo -n $
'\E[36m' ;;
2089 yellow
) echo -n $
'\E[33m' ;;
2090 purple
) echo -n $
'\E[35m' ;;
2091 nocolor
) echo -n $
'\E(B\E[m' ;;
2100 underl
) echo -n $
(tput smul
) ;;
2101 bold
) echo -n $
(tput bold
) ;;
2102 red
) echo -n $
(tput setaf
1) ;;
2103 green
) echo -n $
(tput setaf
2) ;;
2104 blue
) echo -n $
(tput setaf
4) ;;
2105 cyan
) echo -n $
(tput setaf
6) ;;
2106 yellow
) echo -n $
(tput setaf
3) ;;
2107 purple
) echo -n $
(tput setaf
5) ;;
2108 nocolor
) echo -n $
(tput sgr0
) ;; # no font attributes
2118 # Try to keep environment pollution down, EPA loves us.
2119 unset safe_term match_lhs use_color
2126 if [[ $
- == *i
* ]]; then
2127 # git branch/status prompt function
2128 if [[ $OS != Windows_NT
]]; then
2129 GIT_PS1_SHOWDIRTYSTATE
=true
2131 # arch source lopip show -fcation
2132 [[ -r /usr
/share
/git
/git-prompt.sh
]] && source /usr
/share
/git
/git-prompt.sh
2133 # fedora/debian source
2134 [[ -r /usr
/share
/git-core
/contrib
/completion
/git-prompt.sh
]] && source /usr
/share
/git-core
/contrib
/completion
/git-prompt.sh
2136 # in case we didnt source git-prompt.sh
2137 if ! declare -f __git_ps1
> /dev
/null
; then
2143 # this needs to come before next ps1 stuff
2144 # this stuff needs bash 4, feb 2009,
2145 # old enough to no longer condition on $BASH_VERSION anymore
2149 if [[ $
- == *i
* ]] && [[ ! $RLC_INSIDE_EMACS ]]; then
2151 bind -m vi-command B
:shell-backward-word
2152 bind -m vi-command W
:shell-forward-word
2155 if [[ $SSH_CLIENT ||
$SUDO_USER ]]; then
2160 local return=$?
# this MUST COME FIRST
2161 local psc pst ps_char ps_color stale_subvol
2163 history -a # save history
2168 0) ps_color
="$(get_term_color blue)"
2171 1) ps_color
="$(get_term_color green)"
2172 ps_char
="$return \\$"
2174 *) ps_color
="$(get_term_color yellow)"
2175 ps_char
="$return \\$"
2178 if [[ ! -O .
]]; then # not owner
2179 if [[ -w .
]]; then # writable
2180 ps_color
="$(get_term_color bold red)"
2182 ps_color
="$(get_term_color bold green)"
2185 # I would set nullglob, but bash has had bugs where that
2186 # doesnt work if not in top level.
2187 if [[ -e /nocow
/btrfs-stale
]] && ((`command ls -AUq /nocow/btrfs-stale|wc -l`)); then
2188 ps_char
="! $ps_char"
2190 if [[ ! $SSH_CLIENT && $MAIL_HOST != $HOSTNAME ]]; then
2191 ps_char
="@ $ps_char"
2193 PS1
="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
2194 # emacs completion doesnt like the git prompt atm, so disabling it.
2195 #PS1="${PS1%"${PS1#*[wW]}"}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
2197 PROMPT_COMMAND
=prompt-command
2200 if [[ $TERM == screen
* ]]; then
2201 local title_escape
="\033]..2;"
2203 local title_escape
="\033]0;"
2205 if [[ $
* != prompt-command
]]; then
2206 echo -ne "$title_escape$USER@$HOSTNAME ${PWD/#$HOME/~} "
2213 # condition from the screen man page i think.
2214 # note: duplicated in tx()
2215 # disabled. see note in tx
2216 # if [[ $TERM == *(screen*|xterm*|rxvt*) ]]; then
2217 # trap 'settitle "$BASH_COMMAND"' DEBUG
2225 # we also have a file in /a/c/...konsole...
2226 local f
=$HOME/.config
/konsolerc
2227 setini DefaultProfile profileian.profile
"Desktop Entry" $f
2228 setini Favorites profileian.profile
"Favorite Profiles" $f
2229 setini ShowMenuBarByDefault false KonsoleWindow
$f
2230 setini TabBarPosition Top TabBar
$f
2235 setini
$k $v sakura
/a
/c
/subdir_files
/.config
/sakura
/sakura.conf
2237 colorset1_back rgb(33,37,39
2241 disable_numbered_tabswitch true
2242 scroll_lines 10000000
2247 reset-xscreensaver
() {
2248 # except for spash, i set these by setting gui options in
2249 # xscreensaver-command -demo
2250 # then finding the corresponding option in .xscreensaver
2251 # spash, i happened to notice in .xscreensaver
2253 # dpmsOff, monitor doesnt come back on using old free software supported nvidia card
2254 cat > /home
/iank
/.xscreensaver
<<'EOF'
2257 dpmsStandby: 0:02:00
2258 dpmsSuspend: 0:03:00
2262 lockTimeout: 0:03:00
2269 # * stuff that makes sense to be at the end
2270 if [[ "$SUDOD" ]]; then
2273 elif [[ -d /a
]] && [[ $PWD == $HOME ]] && [[ $
- == *i
* ]]; then
2282 # for mitmproxy to get a newer python.
2283 # commented until i want to use it because it
2284 # noticably slows bash startup
2286 #if [[ $EUID != 0 && -e ~/.pyenv/bin ]]; then
2287 # export PATH="~/.pyenv/bin:$PATH"
2288 # eval "$(pyenv init -)"
2289 # eval "$(pyenv virtualenv-init -)"
2294 export GOPATH
=$HOME/go
2295 path_add
$GOPATH/bin
2296 path_add
/usr
/local
/go
/bin
2298 # I have the git repo and a release. either one should work.
2299 # I have both because I was trying to solve an issue that
2300 # turned out to be unrelated.
2301 # ARDUINO_PATH=/a/opt/Arduino/build/linux/work
2302 export ARDUINO_PATH
=/a
/opt
/arduino-1.8
.9
2304 path_add
--end ~
/.npm-global
2306 # taken from default changes to bashrc and bash_profile
2307 path_add
--end $HOME/.rvm
/bin
2308 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
2310 export BASEFILE_DIR
=/a
/bin
/fai-basefiles
2312 export ANDROID_HOME
=/opt
/android
2314 # didnt get drush working, if I did, this seems like the
2315 # only good thing to include for it.
2316 # Include Drush completion.
2317 # if [ -f "/home/ian/.drush/drush.complete.sh" ] ; then
2318 # source /home/ian/.drush/drush.complete.sh
2322 # https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
2323 # i added an extra condition as gentoo xorg guide says depending on
2324 # $DISPLAY is fragile.
2325 if [[ ! $DISPLAY && $XDG_VTNR == 1 ]] && shopt -q login_shell
&& isarch
; then
2330 # ensure no bad programs appending to this file will have an affect