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
19 # remove all aliases. aliases provided by the system tend to get in the way,
20 # for example, error happens if I try to define a function the same name as an alias
23 # remove gnome keyring warning messages
24 # there is probably a more proper way, but I didn't find any easily on google
25 # now using xfce+xmonad instead of vanilla xmonad, so disabling this
26 #unset GNOME_KEYRING_CONTROL
28 # use extra globing features.
30 # include .files when globbing, but ignore files name . and ..
31 # setting this also sets dotglob.
32 # Note, this doesn't work in bash 4.4 anymore, for paths with
33 # more than 1 directory, like a/b/.foo, since * is fixed to not match /
34 export GLOBIGNORE
=*/.
:*/..
36 # broken with bash_completion package. Saw a bug for this once. Don't anymore.
37 # still broken in wheezy
38 # still buggered in latest stable from the web, version 2.1
39 # perhaps its fixed in newer git version, which fails to make for me
40 # this note is from 6-2014.
41 # Also, enabling this before sourcing .bashrc makes PATH be empty.
44 # make tab on an empty line do nothing
45 shopt -s no_empty_cmd_completion
48 # http://bash-completion.alioth.debian.org/
49 # might be sourced by the system already, but I've noticed it not being sourced before
50 if ! type _init_completion
&> /dev
/null
&& [[ -r "/usr/share/bash-completion/bash_completion" ]]; then
51 .
/usr
/share
/bash-completion
/bash_completion
55 # fix spelling errors for cd, only in interactive shell
57 # append history instead of overwritting it
59 # for compatibility, per gentoo/debian bashrc
61 # attempt to save multiline single commands as single history entries.
68 if [[ $RLC_INSIDE_EMACS ]]; then
69 # EMACS is used by bash on startup, but we don't need it anymore.
70 # plus I hit a bug in a makefile which inherited it
72 export RLC_INSIDE_EMACS
75 # scp completion does not work, but this doesn't fix it. todo, figure this out
76 complete
-r scp
&> /dev
/null
77 # todo, remote file completion fails, figure out how to turn it off
78 export NODE_DISABLE_COLORS
=1
79 # This get's rid of ugly terminal escape chars in node repl
80 # sometime, I'd like to have completion working in emacs shell for node
81 # the offending chars can be found in lib/readline.js,
82 # things that do like:
83 # stream.write('\x1b[' + (x + 1) + 'G');
84 # We can remove them and keep readline, for example by doing this
87 # var readline = require('readline');
88 # readline.cursorTo = function(a,b,c) {};
89 # readline.clearScreenDown = function(a) {};
90 # const repl = require('repl');
91 # var replServer = repl.start('');
93 # no prompt, or else readline complete seems to be confused, based
94 # on our column being different? node probably needs to send
95 # different kind of escape sequence that is not ugly. Anyways,
96 # completion doesn't work yet even with the ugly prompt, so whatever
98 export NODE_NO_READLINE
=1
103 if [[ $
- == *i
* ]]; then
104 # for readline-complete.el
105 if [[ $RLC_INSIDE_EMACS ]]; then
106 # all for readline-complete.el
108 bind 'set horizontal-scroll-mode on'
109 bind 'set print-completions-horizontally on'
110 bind '"\C-i": self-insert'
112 # arrow keys. for other terminals, see http://unix.stackexchange.com/questions/10806/how-to-change-previous-next-word-shortcut-in-bash
113 if [[ $TERM == "xterm" ]]; then
114 bind '"\e[1;5C": shell-forward-word' 2>/dev
/null
115 bind '"\e[1;5D": shell-backward-word' 2>/dev
/null
117 bind '"\eOc": shell-forward-word'
118 bind '"\eOd": shell-backward-word'
120 # terminal keys: C-c, C-z. the rest defined by stty -a are, at least in
121 # gnome-terminal, overridden by bash, or disabled by the system
122 stty werase undef lnext undef stop undef start undef
129 # history number. History expansion is good.
131 # history file size limit, set to unlimited.
132 # this needs to be different from the default because
133 # default HISTFILESIZE is 500 and could clobber our history
135 # max commands 1 session can append/read from history
137 # my own history size limit based on lines
138 HISTFILELINES
=1000000
140 # the time format display when doing the history command
141 # also, setting this makes the history file record time
142 # of each command as seconds from the epoch
143 HISTTIMEFORMAT
="%I:%M %p %m/%d "
144 # consecutive duplicate lines don't go in history
145 HISTCONTROL
=ignoredups
146 # works in addition to HISTCONTROL to do more flexible things
147 # it could also do the same things as HISTCONTROL and thus replace it,
148 # but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
149 HISTIGNORE
='k *:[ ]*'
151 export BC_LINE_LENGTH
=0
154 # note, if I use a machine I don't want files readable by all users, set
155 # umask 077 # If fewer than 4 digits are entered, leading zeros are assumed
163 for _x
in /a
/bin
/distro-functions
/src
/* /a
/bin
/!(githtml
)/*-function?
(s
); do
167 # so I can share my bashrc
168 for x
in /a
/bin
/bash_unpublished
/source-
!(.
#*); do source $x; done
169 source $
(dirname $
(readlink
-f $BASH_SOURCE))/path_add-function
170 source /a
/bin
/log-quiet
/logq-function
172 path_add
--ifexists --end /a
/opt
/adt-bundle
*/tools
/a
/opt
/adt-bundle
*/platform-tools
173 # based on readme.debian. dunno if this will break on other distros.
174 _x
=/usr
/share
/wcd
/wcd-include.sh
175 if [[ -e $_x ]]; then source $_x; fi
182 # very few aliases, functions are always preferred.
185 if [[ $OS == Windows_NT
]]; then
186 alias ffs
='cygstart "/c/Program Files (x86)/Mozilla Firefox/firefox.exe" -P scratch'
188 alias j
='command cygpath'
189 alias t
='command cygstart'
190 alias cygstart
='echo be quick, use the alias "t" instead :\)'
191 alias cygpath
='echo be quick, use the alias "j" instead :\)'
196 # keep this in mind? good for safety.
201 # remove any default aliases for these
202 unalias ls ll
grep &>/dev
/null ||
:
212 #####################
214 #####################
219 ....
() { c ..
/..
/..
; }
220 .....
() { c ..
/..
/..
/..
; }
221 ......
() { c ..
/..
/..
/..
/..
; }
224 # file cut copy and paste, like the text buffers :)
225 # I havn't tested these.
226 _fbufferinit
() { # internal use by
227 ! [[ $my_f_tempdir ]] && my_f_tempdir
=$
(mktemp
-d)
228 rm -rf "$my_f_tempdir"/*
232 cp "$@" "$my_f_tempdir"/
236 mv "$@" "$my_f_tempdir"/
238 fpst
() { # file paste
239 [[ $2 ]] && { echo too many arguments
; return 1; }
241 cp "$my_f_tempdir"/* "$target"
246 complete
-F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr
250 # join options which are continued to multiples lines onto one line
252 grep -vE '^([ \t]*#|^[ \t]*$)' "$1" |
while IFS
= read -r line
; do
253 # remove leading spaces/tabs. assumes extglob
254 if [[ $line == "[ ]*" ]]; then
260 elif [[ $line == *=* ]]; then
261 echo "$pastline" >> "$2"
264 pastline
="$pastline $line"
267 echo "$pastline" >> "$2"
272 ssh-keygen
-R $h -f $
(readlink
-f ~
/.ssh
/known_hosts
)
273 local x
=$
(timeout
0.1 ssh -v $1 |
& sed -rn "s/debug1: Connecting to $h \[([^\]*)].*/\1/p");
274 ssh-keygen
-R $x -f $
(readlink
-f ~
/.ssh
/known_hosts
)
276 khfix
() { # known hosts fix
289 ack
() { ack-grep
"$@"; }
292 # googling android emulator libGL error: failed to load driver: r600
293 # lead to http://stackoverflow.com/a/36625175/14456
294 export ANDROID_EMULATOR_USE_SYSTEM_LIBS
=1
295 /a
/opt
/android-studio
/bin
/studio.sh
"$@" &r
;
304 # use -p from interactive shell
308 bfg
() { java
-jar /a
/opt
/bfg-1.12
.14.jar
"$@"; }
311 local f
=/etc
/bitcoin
/bitcoin.conf
312 bitcoin-cli
-$
(s
grep rpcuser
= $f) -$
(s
grep rpcpassword
= $f) "$@"
317 price
="$(curl -s https://blockchain.info/ticker | jq .USD.last)"
318 printf "$%s\n" "$price"
320 printf "$%.2f\n" "$(echo "scale
=2; $price * $1"| bc -l)"
325 if [[ $RLC_INSIDE_EMACS ]]; then
326 c
() { wcd
-c -z 50 -o "$@"; }
328 # lets see what the fancy terminal does from time to time
329 c
() { wcd
-c -z 50 "$@"; }
332 caa
() { git commit
--amend --no-edit -a; }
334 calc
() { echo "scale=3; $*" |
bc -l; }
335 # no having to type quotes, but also no command history:
339 echo "scale=3; $x" |
bc -l
346 ccat
() { # config cat. see a config without extra lines.
347 grep '^\s*[^[:space:]#]' "$@"
352 # setup for format of postfix, eg:
356 local unified
="$(mktemp)"
359 _cdiff-prep
"$1" "$f1"
360 _cdiff-prep
"$2" "$f2"
361 cat "$f1" "$f2" |
grep -Po '^[^=]+=' |
sort |
uniq > "$unified"
362 while IFS
= read -r line
; do
363 # the default bright red / blue doesn't work in emacs shell
364 dwdiff
-cblue,red
-A best
-d " ," <(grep "^$line" "$f1" ||
echo ) <(grep "^$line" "$f2" ||
echo ) | colordiff
371 cp /a
/bin
/data
/COPYING
"$@"
373 cp /a
/bin
/data
/COPYING .
379 cp /a
/bin
/data
/LICENSE
"$@"
381 cp /a
/bin
/data
/LICENSE .
385 # makes it so chown -R symlink affects the symlink and its target.
386 if [[ $1 == -R ]]; then
388 command chown
-h "$@"
389 command chown
-R "$@"
400 # choose recent directory. cl = cd list
405 complete
-A stopped
-P '"%' -S '"' d
407 dat
() { # do all tee, for more complex scripts
408 tee >(ssh frodo bash
-l) >(bash
-l) >(ssh x2 bash
-l) >(ssh tp bash
-l)
413 for host in x2 tp treetowl
; do
419 diff --strip-trailing-cr -w "$@" # diff content
422 debian_pick_mirror
() {
423 # netselect-apt finds a fast mirror.
424 # but we need to replace the mirrors ourselves,
425 # because it doesn't do that. best it can do is
426 # output a basic sources file
427 # here we get the server it found, get the main server we use
428 # then substitute all instances of one for the other in the sources file
429 # and backup original to /etc/apt/sources.list-original.
430 # this is idempotent. the only way to identify debian sources is to
431 # note the original server, so we put it in a comment so we can
433 local file=$
(mktemp
-d)/f
# safe way to get file name without creating one
434 sudo netselect-apt
-o "$file" ||
return 1
435 url
=$
(grep ^
\\w
$file |
head -n1 |
awk '{print $2}')
436 sudo
cp -f /etc
/apt
/sources.list
/etc
/apt
/sources.list-original
437 sudo
sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc
/apt
/sources.list
445 safe_rename
"$x" "$y"
450 date "+%A, %B %d, %r" "$@"
454 du
-sh ${@:-*} |
sort -h
463 [[ ${#@} == 2 ]] ||
{ echo "error: ediff requires 2 arguments"; return 1; }
464 emacs
--eval "(ediff-files \"$1\" \"$2\")"
468 envload
() { # load environment from a previous: export > file
469 local file=${1:-$HOME/.${USER}_env}
470 eval "$(export | sed 's/^declare -x/export -n/')"
471 while IFS
= read -r line
; do
472 # declare -x makes variables local to a function
473 eval ${line/#declare -x/export}
483 # find array. make an array of file names found by find into $x
484 # argument: find arguments
485 # return: find results in an array $x
486 while read -rd ''; do
488 done < <(find "$@" -print0);
491 faf
() { # find all files
495 fastboot
() { /a
/opt
/androidsdk
/platform-tools
/fastboot
"$@"; }
498 if type -P firefox
&>/dev
/null
; then
508 firefox
-P alt
"$@" >/dev
/null
2>&1
514 local dname
="${PWD##*/}"
515 local m
="/a/tmp/$dname-missing"
516 local d
="/a/tmp/$dname-diff"
517 [[ -e $d ]] && rm "$d"
518 [[ -e $m ]] && rm "$m"
521 while read -r line
; do
523 if [[ -e "$fsfile" ]]; then
524 md5diff
"$line" "$fsfile" && tee -a "/a/tmp/$dname-diff" <<< "$fsfile $line"
530 done < <(find -type f
)
533 (( msize
<= 100 )) && cat $m
537 # expected output, with different tmp dirs
538 # /tmp/tmp.HDPbwMqdC9/c/d ./c/d
539 # /a/tmp/tmp.qLDkYxBYPM-missing
548 echo different
> $x/c
/d
553 # test whether missing files were renamed, generally for use with fsdiff
554 # $1 = fsdiff output file, $2 = directory to compare to. pwd = fsdiff dir
555 # echos non-renamed files
559 { sums
+=( "$(md5sum < "$x")" ) ; } 2>/dev
/null
561 while read -r line
; do
562 { missing_sum
=$
(md5sum < "$line") ; } 2>/dev
/null
564 for x
in "${sums[@]}"; do
565 if [[ $missing_sum == "$x" ]]; then
570 $renamed ||
echo "$line"
576 # F = fullscren, z = random, Z = auto zoom
577 command feh
-FzZ "$@"
581 # like -e for functions. returns on error.
582 # at the end of the function, disable with:
584 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
585 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"
592 firefox
-P default
"$@" >/dev
/null
2>&1
596 local help="Usage: getdir [--help] PATH
597 Output the directory of PATH, or just PATH if it is a directory."
598 if [[ $1 == --help ]]; then
602 if [[ $# -ne 1 ]]; then
603 echo "getdir error: expected 1 argument, got $#"
609 local dir
="$(dirname "$1")"
610 if [[ -d $dir ]]; then
613 echo "getdir error: directory does not exist"
619 git_empty_branch
() { # start an empty git branch. carefull, it deletes untracked files.
620 [[ $# == 1 ]] ||
{ echo 'need a branch name!'; return 1;}
622 gitroot ||
return 1 # function to set gitroot
623 builtin cd "$gitroot"
624 git symbolic-ref HEAD refs
/heads
/$1
630 local help="Usage: gitroot [--help]
631 Print the full path to the root of the current git repo
633 Handles being within a .git directory, unlike git rev-parse --show-toplevel,
634 and works in older versions of git which did not have that."
635 if [[ $1 == --help ]]; then
639 local p
=$
(git rev-parse
--git-dir) ||
{ echo "error: not in a git repo" ; return 1; }
640 [[ $p != /* ]] && p
=$PWD
645 # quit will prompt if the program crashes.
646 gdb
-ex=r
-ex=quit
--args emacs
"$@"; r
;
650 # kill the emacs daemon
655 git send-email
--notes '--envelope-sender=<ian@iankelling.org>' \
656 --suppress-cc=self
"$@"
660 grep -iIP --color=auto
"$@"
664 if [[ ${#@} == 1 ]]; then
665 grep -riIP --color=auto
"$@" .
667 grep -riIP --color=auto
"$@"
672 # do git status on published repos
674 for x
in !(forks
) forks
/* ian-specific
/*; do
675 cd `readlink -f $x`/..
683 hl
() { # history limit. Write extra history to archive file.
684 # todo: this is not working or not used currently
685 local max_lines linecount tempfile prune_lines x
686 local harchive
="${HISTFILE}_archive"
687 for x
in "$HISTFILE" "$harchive"; do
688 [[ -e $x ]] ||
{ touch "$x" && echo "notice from hl(): creating $x"; }
689 if [[ ! $x ||
! -e $x ||
! -w $x || $
(stat
-c "%u" "$x") != $EUID ]]; then
690 echo "error in hl: history file \$x:$x no good"
694 history -a # save history
695 max_lines
=$HISTFILELINES
696 [[ $max_lines =~ ^
[0-9]+$
]] ||
{ echo "error in hl: failed to get max line count"; return 1; }
697 linecount
=$
(wc -l < $HISTFILE) # pipe so it doesn't output a filename
698 [[ $linecount =~ ^
[0-9]+$
]] ||
{ echo "error in hl: wc failed"; return 1; }
699 if (($linecount > $max_lines)); then
700 prune_lines
=$
(($linecount - $max_lines))
701 head -n $prune_lines "$HISTFILE" >> "$harchive" \
702 && sed --follow-symlinks -ie "1,${prune_lines}d" $HISTFILE
706 hr
() { # horizontal row. used to break up output
707 printf "$(tput setaf 5)â–ˆ$(tput sgr0)%.0s" $
(seq $COLUMNS)
711 hrcat
() { local f
; for f
; do [[ -f $f ]] ||
continue; hr
; echo "$f"; cat "$f"; done }
715 # modified from ~/local/bin/git-completion.bash
716 # other completion commands are mostly taken from bash_completion package
717 complete
-o bashdefault
-o default
-o nospace
-F _git i
2>/dev
/null \
718 || complete
-o default
-o nospace
-F _git i
720 if ! type service
&>/dev
/null
; then
722 echo actually running
: systemctl
$2 $1
733 /a
/opt
/idea-IC-163.7743
.44/bin
/idea.sh
"$@" &r
738 find -L .
-not \
( -name .svn
-prune -o -name .git
-prune \
739 -o -name .hg
-prune -o -name .editor-backups
-prune \
740 -o -name .undo-tree-history
-prune \
) -iname "*$**" 2>/dev
/null
744 if [[ $OS == Windows_NT
]]; then
755 (( ${#x[#]} > 1 )) && { echo "warning ${#x[#]} matches found"; sleep 1; }
760 if type gvfs-open
&> /dev
/null
; then
765 # another alternative is run-mailcap
772 grep -Il "" "$@" &>/dev
/null
776 journalctl
-n 10000 -f "$@" |
grep -Evi "^(\S+\s+){4}(sudo|sshd|cron)"
781 if [[ $PWD == /[iap
] ]]; then
782 command ls -A --color=auto
-I lost
+found
"$@"
784 command ls -A --color=auto
"$@"
789 lcn
() { locate -i "*$**"; }
791 lld
() { ll
-d "$@"; }
793 low
() { # make filenames all lowercase
796 y
=$
(tr "[A-Z]" "[a-z]" <<<"$x")
797 [[ $y != $x ]] && mv "$x" "$y"
804 lower
() { # make first letter of filenames lowercase.
807 if [[ ${x::1} == [A-Z
] ]]; then
808 y
=$
(tr "[A-Z]" "[a-z]" <<<"${x::1}")"${x:1}"
809 safe_rename
"$x" "$y"
815 k
() { # history search
816 grep -P --binary-files=text
"$@" ${HISTFILE:-~/.bash_history} |
tail -n 80;
821 # show make targets, via http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make
822 make -qp |
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
831 mkdir
() { command mkdir
-p "$@"; }
835 export PYTHONPATH
=/a
/opt
/Pithosfly
840 # from http://askubuntu.com/questions/456021/remove-vocals-from-mp3-and-get-only-instrumentals
841 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
845 pfind
() { #find *$1* in $PATH
846 [[ $# != 1 ]] && { echo requires
1 argument
; return 1; }
848 IFS
=: pathArray
=($PATH); unset IFS
849 find "${pathArray[@]}" -iname "*$1*"
854 pid
=($
(pgrep
-f "$*"))
860 0) echo "no pid found" ;;
868 # trash-restore lists everything that has been trashed at or below CWD
869 # This picks out files just in CWD, not subdirectories,
870 # which also match grep $1, usually use $1 for a time string
871 # which you get from running restore-trash once first
874 # last condition is to not ask again for ones we skipped
875 while name
="$( echo | restore-trash | gr "$PWD/[^
/]\
+$
" | gr "$1" )" \
876 && [[ $name ]] && (( $
(wc -l <<<"$name") >= nth
)); do
877 name
="$(echo "$name" | head -n $nth | tail -n 1 )"
878 read -p "$name [Y/n] " ask
879 if [[ ! $ask ||
$ask == [Yy
] ]]; then
880 x
=$
( echo "$name" | gr
-o "^\s*[0-9]*" )
881 echo $x | restore-trash
> /dev
/null
882 elif [[ $ask == [Nn
] ]]; then
894 [[ $EUID == 0 ]] || s
=s
895 $s postconf
-ev "${MAPFILE[@]}"
899 rld
/a
/h
/_site
/ li
:/var
/www
/iankelling.org
/html
902 pubip
() { curl
-4s https
://icanhazip.com
; }
903 whatismyip
() { pubip
; }
909 # -t = print pronunciation
914 # -M CLN = use Caps, Lowercase, Numbers
916 # -a 1 = use random instead of pronounceable algorithm
917 apg
-m 50 -x 70 -n 1 -a 1 -M CLN
921 q
() { # start / launch a program in the backround and redir output to null
926 exit "$@" 2>/dev
/null
929 rbpipe
() { rbt post
-o --diff-filename=- "$@"; }
930 rbp
() { rbt post
-o "$@"; }
933 # rsync, root is required to keep permissions right.
934 # rsync --archive --human-readable --verbose --itemize-changes --checksum \(-ahvic\) \
935 # --no-times --delete
936 # basically, make an exact copy, use checksums instead of file times to be more accurate
937 rsync
-ahvic --delete "$@"
940 # like rlu, but don't delete files on the target end which
941 # do not exist on the original end.
944 complete
-F _rsync
-o nospace rld rl rlt
947 # rl without preserving modification time.
948 rsync
-ahvic --delete --no-t "$@"
951 rlu
() { # [OPTS] HOST PATH
952 # eg. rlu -opts frodo /testpath
953 # relative paths will expanded with readlink -f.
954 # useful for selectively sending dirs which have been synced with unison,
955 # where the path is the same on both hosts.
956 opts
=("${@:1:$#-2}") # 1 to last -2
957 path
="${@:$#}" # last
958 host="${@:$#-1:1}" # last -1
959 if [[ $path == .
* ]]; then
960 path
=$
(readlink
-f $path)
962 # rync here uses checksum instead of time so we don't mess with
963 # unison relying on time as much. g is for group, same reason
964 # to keep up with unison.
965 s rsync
-rlpchviog --relative "${opts[@]}" "$path" "root@$host:/";
969 rspicy
() { # usage: HOST DOMAIN
970 # connect to spice vm remote host. use vspicy for local host
971 local port
=$
(ssh $1<<EOF
972 sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
973 sed -rn "s/.*port='([0-9]+).*/\1/p"
979 echo "error: no port found. check that the domain is running."
985 # I use a function because otherwise we can't use in a script,
986 # can't assign to variable.
988 # note: gksudo is recommended for X apps because it does not set the
989 # home directory to the same, and thus apps writing to ~ fuck things up
990 # with root owned files.
992 if [[ $EUID != 0 ||
$1 == -* ]]; then
993 SUDOD
="$PWD" sudo
-i "$@"
1000 if [[ $# != 2 ]]; then
1001 echo safe_rename error
: $# args
, need
2 >2
1003 elif [[ $1 != $2 ]]; then
1004 if [[ -e $2 ]]; then
1005 echo Cannot rename
"$1" to
"$2" as it already exists.
1013 sb
() { # sudo bash -c
1014 # use sb instead of s is for sudo redirections,
1015 # eg. sb 'echo "ok fine" > /etc/file'
1017 sudo
-i bash
-c "$@"
1019 complete
-F _root_command s sb
1022 # s gem install scss-lint
1023 pushd /a
/opt
/thoughtbot-guides
1026 scss-lint
-c /a
/opt
/thoughtbot-guides
/style
/sass
/.scss-lint.yml
"$@"
1030 local s
; [[ $EUID != 0 ]] && s
=sudo
1031 if type -p systemctl
&>/dev
/null
; then
1038 sgo
() { # service go
1040 ser restart
$service
1041 if type -p systemctl
&>/dev
/null
; then
1048 # 2086 = unquoted $var
1049 # 2046 = unquoted $(cmd)
1050 # i had -x as an arg, but debian testing(stretch) doesn't support it
1051 shellcheck
-e 2086,2046,2068,2006,2119 "$@"
1056 # log with script. timing is $1.t and script is $1.s
1057 # -l to save to ~/typescripts/
1058 # -t to add a timestamp to the filenames
1059 local logdir do_stamp arg_base
1060 (( $# >= 1 )) ||
{ echo "arguments wrong"; return 1; }
1063 while getopts "lt" option
1066 l
) arg_base
=$logdir ;;
1067 t
) do_stamp
=true
;;
1070 shift $
(($OPTIND - 1))
1072 [[ -e $logdir ]] || mkdir
-p $logdir
1073 $do_stamp && arg_base
+=$
(date +%F.
%T
%z
)
1074 script -t $arg_base.s
2> $arg_base.t
1076 splay
() { # script replay
1077 #logRoot="$HOME/typescripts/"
1078 #scriptreplay "$logRoot$1.t" "$logRoot$1.s"
1079 scriptreplay
"$1.t" "$1.s"
1083 # sudo redo. be aware, this command may not work right on strange distros or earlier software
1084 if [[ $# == 0 ]]; then
1085 sudo
-E bash
-c -l "$(history -p '!!')"
1087 echo this
command redos last
history item. no argument is accepted
1092 # with -ll, less secure but faster.
1093 command srm
-ll "$@"
1098 ssh $1 /tmp
/${2##*/} "${@:2}"
1112 if type -t trash-put
>/dev
/null
; then
1113 # skip args that don't exist, or else trash-put will have an error
1115 if [[ -e $x ||
-L $x ]]; then
1119 [[ ! ${args[@]} ]] || trash-put
"${args[@]}"
1130 # this goes to full width
1131 #len=${1:-$((COLUMNS -7))}
1134 if (( x
== len
)); then
1136 d
="$(date +%l:%_M) "
1139 d
=$
(date +%l
:%M
:%_S
)
1143 for ((i
=0; i
<x
; i
++)); do
1144 if (( i
% 6 )); then
1162 # test existence / exists
1165 [[ -e "$x" ||
-L "$x" ]] || ret
=1
1171 declare -gi _seq
; _seq
+=1
1172 echo "test body" | m
mail -s "test mail from $HOSTNAME, $_seq" "${1:-root@localhost}"
1177 (sleep $
(calc
"$@ * 60") && mpv
--volume 50 /a
/bin
/data
/alarm.mp3
--loop=no
) > /dev
/null
2>&1 &
1183 local dir
="$(dirname "$1")"
1184 if [[ -e $1 && ! -w $1 ||
! -w $
(dirname "$1") ]]; then
1190 tx
() { # toggle set -x, and the prompt so it doesn't spam
1191 if [[ $
- == *x
* ]]; then
1193 PROMPT_COMMAND
=prompt_command
1195 unset PROMPT_COMMAND
1202 # show all processes in the network namespace $1.
1203 # blank entries appear to be subprocesses/threads
1207 s
find -L /proc
/[1-9]*/task
/*/ns
/net
-samefile /run
/netns
/$netns | cut
-d/ -f5 | \
1209 x
=$
(ps
-w --no-headers -p $l);
1210 if [[ $x ]]; then echo "$x"; else echo $l; fi;
1214 m
() { printf "%s\n" "$*"; "$@"; }
1218 m s nsenter
-t $
(pgrep
-f "/usr/sbin/openvpn --suppress-timestamps --nobind --config /etc/openvpn/client/client.conf") -n -m "$@"
1221 vpncmd gksudo
-u ian firefox
&r
1228 trg
() { transmission-remote-gtk
&r
; }
1231 # local pid=$(cat /var/lib/transmission-daemon/transmission-daemon.pid)
1232 # if [[ $pid && -e /proc/$pid ]]; then
1233 # echo "noop. already running."
1237 # local NAME=transmission-daemon
1238 # local DAEMON=/usr/bin/$NAME
1239 # local duser=debian-transmission
1241 # [ -e /etc/default/$NAME ] && . /etc/default/$NAME
1242 # s ip netns exec vpn sudo -u $duser ionice -c 3 nice -n 19 $DAEMON $OPTIONS
1246 for x
in "$@"; do virsh destroy
"$x"; virsh undefine
"$x"; done
1253 s virsh dumpxml
$vm |
sed -r "s/(<listen.*address=')([^']+)/\1$ip/" | \
1254 sed -r "s/listen='[^']+/listen='$ip/"> $t
1255 s virsh undefine
$vm
1261 vm-set-listen
$1 0.0.0.0
1266 vm-set-listen
$1 127.0.0.1
1270 s systemctl start openvpn@client
&
1271 journalctl
--unit=openvpn@client
-f -n0
1276 s systemctl stop openvpn@client
1287 vspicy
() { # usage: VIRSH_DOMAIN
1288 # connect to vms made with virt-install
1289 spicy
-p $
(sudo virsh dumpxml
"$1"|
grep "<graphics.*type='spice'"|\
1290 sed -r "s/.*port='([0-9]+).*/\1/")
1294 whatismyip
() { curl ipecho.net
/plain
; echo; }
1297 #############################
1298 ######### misc stuff ########
1299 #############################
1301 if [[ $
- == *i
* ]]; then
1302 # commands to run when bash exits normally
1307 # temporary variables to test colorization
1308 # some copied from gentoo /etc/bash/bashrc,
1310 # dircolors --print-database uses its own built-in database
1311 # instead of using /etc/DIR_COLORS. Try to use the external file
1312 # first to take advantage of user additions.
1313 safe_term
=${TERM//[^[:alnum:]]/?} # sanitize TERM
1315 [[ -f ~
/.dir_colors
]] && match_lhs
="${match_lhs}$(<~/.dir_colors)"
1316 [[ -f /etc
/DIR_COLORS
]] && match_lhs
="${match_lhs}$(</etc/DIR_COLORS)"
1317 [[ -z ${match_lhs} ]] \
1318 && type -P dircolors
>/dev
/null \
1319 && match_lhs
=$
(dircolors
--print-database)
1320 # test if our $TERM is in the TERM values in dircolor
1321 [[ $
'\n'${match_lhs} == *$
'\n'"TERM "${safe_term}* ]] && use_color
=true
1324 if ${use_color} && [[ $
- == *i
* ]]; then
1326 if [[ $XTERM_VERSION == Cygwin
* ]]; then
1330 underl
) echo -n $
'\E[4m' ;;
1331 bold
) echo -n $
'\E[1m' ;;
1332 red
) echo -n $
'\E[31m' ;;
1333 green
) echo -n $
'\E[32m' ;;
1334 blue
) echo -n $
'\E[34m' ;;
1335 cyan
) echo -n $
'\E[36m' ;;
1336 yellow
) echo -n $
'\E[33m' ;;
1337 purple
) echo -n $
'\E[35m' ;;
1338 nocolor
) echo -n $
'\E(B\E[m' ;;
1347 underl
) echo -n $
(tput smul
) ;;
1348 bold
) echo -n $
(tput bold
) ;;
1349 red
) echo -n $
(tput setaf
1) ;;
1350 green
) echo -n $
(tput setaf
2) ;;
1351 blue
) echo -n $
(tput setaf
4) ;;
1352 cyan
) echo -n $
(tput setaf
6) ;;
1353 yellow
) echo -n $
(tput setaf
3) ;;
1354 purple
) echo -n $
(tput setaf
5) ;;
1355 nocolor
) echo -n $
(tput sgr0
) ;; # no font attributes
1365 # Try to keep environment pollution down, EPA loves us.
1366 unset safe_term match_lhs use_color
1378 if [[ $
- == *i
* ]]; then
1379 # git branch/status prompt function
1380 if [[ $OS != Windows_NT
]]; then
1381 GIT_PS1_SHOWDIRTYSTATE
=true
1383 # arch source lopip show -fcation
1384 [[ -r /usr
/share
/git
/git-prompt.sh
]] && source /usr
/share
/git
/git-prompt.sh
1385 # fedora/debian source
1386 [[ -r /usr
/share
/git-core
/contrib
/completion
/git-prompt.sh
]] && source /usr
/share
/git-core
/contrib
/completion
/git-prompt.sh
1388 # in case we didn't source git-prompt.sh
1389 if ! declare -f __git_ps1
> /dev
/null
; then
1395 # this needs to come before next ps1 stuff
1396 # this stuff needs bash 4, feb 2009,
1397 # old enough to no longer condition on $BASH_VERSION anymore
1401 if [[ $
- == *i
* ]] && [[ ! $RLC_INSIDE_EMACS ]]; then
1403 bind -m vi-command B
:shell-backward-word
1404 bind -m vi-command W
:shell-forward-word
1407 if [[ $SSH_CLIENT ]]; then
1412 local return=$?
# this MUST COME FIRST
1413 local psc pst ps_char ps_color stale_subvol
1415 history -a # save history
1418 if [[ ! $DESKTOP_SESSION == xmonad
&& $TERM == *(screen
*|xterm
*|rxvt
*) ]]; then
1419 # from the screen man page
1420 if [[ $TERM == screen
* ]]; then
1421 local title_escape
="\033]..2;"
1423 local title_escape
="\033]0;"
1425 echo -ne "$title_escape${PWD/#$HOME/~} $USER@$HOSTNAME\007"
1430 0) ps_color
="$(get_term_color blue)"
1433 1) ps_color
="$(get_term_color green)"
1434 ps_char
="$return \\$"
1436 *) ps_color
="$(get_term_color yellow)"
1437 ps_char
="$return \\$"
1440 if [[ ! -O .
]]; then # not owner
1441 if [[ -w .
]]; then # writable
1442 ps_color
="$(get_term_color bold red)"
1444 ps_color
="$(get_term_color bold green)"
1447 # I would set nullglob, but bash has had bugs where that
1448 # doesn't work if not in top level.
1449 if [[ -e /nocow
/btrfs-stale
]] && ((`ls -AUq /nocow/btrfs-stale|wc -l`)); then
1450 ps_char
="! $ps_char"
1452 PS1
="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
1453 # emacs completion doesn't like the git prompt atm, so disabling it.
1454 #PS1="${PS1%"${PS1#*[wW]}"}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
1456 PROMPT_COMMAND
=prompt_command
1461 ###########################################
1462 # stuff that makes sense to be at the end #
1463 ###########################################
1464 if [[ "$SUDOD" ]]; then
1467 elif [[ -d /a
]] && [[ $PWD == $HOME ]] && [[ $
- == *i
* ]]; then
1476 # if someone exported $SOE, catch errors
1481 # I'd prefer to have system-wide, plus user ruby, due to bug in it
1482 # https://github.com/rubygems/rubygems/pull/1002
1483 # further problems: installing multi-user ruby and user ruby,
1484 # you don't get multi-user ruby when you sudo to root, unless its sudo -i.
1485 # There a third hybrid form, which passenger error suggested I use,
1486 # but it didn't actually work.
1488 # in cased I never need this
1489 # rvm for non-interactive shell: modified from https://rvm.io/rvm/basics
1490 #if [[ $(type -t rvm) == file && ! $(type -t ruby) ]]; then
1491 # source $(rvm 1.9.3 do rvm env --path)
1494 # based on warning from rvmsudo
1495 export rvmsudo_secure_path
=1
1497 # for other script I wrote
1498 #export ACME_TINY_PATH=/a/opt/acme-tiny
1499 export ACME_TINY_WRAPPER_CERT_DIR
=/p
/c
/machine_specific
/$HOSTNAME/webservercerts
1501 if [[ -s "/usr/local/rvm/scripts/rvm" ]]; then
1502 source "/usr/local/rvm/scripts/rvm"
1503 elif [[ -s $HOME/.rvm
/scripts
/rvm
]]; then
1504 source $HOME/.rvm
/scripts
/rvm
1508 path_add
--end ~
/.npm-global
1511 # didn't get drush working, if I did, this seems like the
1512 # only good thing to include for it.
1513 # Include Drush completion.
1514 # if [ -f "/home/ian/.drush/drush.complete.sh" ] ; then
1515 # source /home/ian/.drush/drush.complete.sh
1519 # https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
1520 # i added an extra condition as gentoo xorg guide says depending on
1521 # $DISPLAY is fragile.
1522 if [[ ! $DISPLAY && $XDG_VTNR == 1 ]] && shopt -q login_shell
&& isarch
; then
1527 # ensure no bad programs appending to this file will have an affect