intermediate commit
[distro-setup] / .bashrc
diff --git a/.bashrc b/.bashrc
index 3725a9f1a56594f2fc3ae7998db933b9ffcd4d52..d63c6bd6d663075bf3918cab547725d1a18f5acf 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -198,8 +198,8 @@ HISTTIMEFORMAT="%I:%M %p %m/%d "
 HISTCONTROL=ignoredups
 # works in addition to HISTCONTROL to do more flexible things
 # it could also do the same things as HISTCONTROL and thus replace it,
-# but meh
-HISTIGNORE='k **'
+# but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
+HISTIGNORE='k *:[ ]*'
 
 export BC_LINE_LENGTH=0
 
@@ -359,6 +359,13 @@ bashrcpush () {
     cd "$startdir"
 }
 
+bfg() { java -jar /a/opt/bfg-1.12.14.jar "$@"; }
+
+btc() {
+    local f=/etc/bitcoin/bitcoin.conf
+    bitcoin-cli -$(s grep rpcuser= $f) -$(s grep rpcpassword= $f) "$@"
+}
+
 caa() { git commit --amend --no-edit -a; }
 
 calc() { echo "scale=3; $*" | bc -l; }
@@ -509,6 +516,11 @@ fa() {
     done < <(find "$@" -print0);
 }
 
+faf() { # find all files
+    find $@ -type f
+}
+
+fastboot() { /a/opt/androidsdk/platform-tools/fastboot "$@"; }
 
 ff() {
     if type -P firefox &>/dev/null; then
@@ -716,6 +728,8 @@ hr() { # horizontal row. used to break up output
     echo
 }
 
+hrcat() { local f; for f; do [[ -f $f ]] || continue; hr; echo "$f"; cat "$f"; done }
+
 
 i() { git "$@"; }
 # modified from ~/local/bin/git-completion.bash
@@ -735,6 +749,9 @@ ic() {
     git commit -am "$*"
 }
 
+idea() {
+    /a/opt/idea-IC-163.7743.44/bin/idea.sh "$@" &r
+}
 
 ifn() {
     # insensitive find
@@ -774,6 +791,10 @@ istext() {
     grep -Il "" "$@" &>/dev/null
 }
 
+jtail() {
+    journalctl -n 10000 -f "$@" | grep -Evi "^(\S+\s+){4}(sudo|ovpn|sshd|cron)"
+}
+
 
 l() {
     if [[ $PWD == /[iap] ]]; then
@@ -829,7 +850,8 @@ mkc() {
 mkdir() { command mkdir -p "$@"; }
 
 pithos() {
-    cd /a/opt/Pithosfly/
+    cd /
+    export PYTHONPATH=/a/opt/Pithosfly
     python3 -m pithos&r
 }
 
@@ -886,6 +908,9 @@ whatismyip() { pubip; }
 
 
 pwgen() {
+    # -m = min length
+    # -x = max length
+    # -t = print pronunciation
     apg -m 12 -x 16 -t
 }
 
@@ -921,7 +946,7 @@ rlt() {
 }
 
 rlu() { # [OPTS] HOST PATH
-    # eg rlu -opts frodo testpath
+    # eg rlu -opts frodo /testpath
     # useful for selectively sending dirs which have been synced with unison,
     # where the path is the same on both hosts.
     opts=("${@:1:$#-2}") #  1 to last -2
@@ -1067,6 +1092,14 @@ srun() {
     ssh $1 /tmp/${2##*/} "${@:2}"
 }
 
+swap() {
+    local tmp
+    tmp=$(mktemp)
+    mv $1 $tmp
+    mv $2 $1
+    mv $tmp $2
+}
+
 t() {
     local x
     local -a args
@@ -1185,8 +1218,18 @@ tx() { # toggle set -x, and the prompt so it doesn't spam
     fi
 }
 
-vc() {
-    [[ $1 ]] || { e "$0: error, expected cmd to run"; return 1; }
+psnsvpn() {
+    # show all processes in the vpn network namespace.
+    # blank entries appear to be subprocesses/threads of transmission daemon
+    ps -w | head -n 1
+    s find -L /proc/[1-9]*/task/*/ns/net -samefile /run/netns/vpn | cut -d/ -f5 | \
+        while read l; do
+            x=$(ps -w --no-headers -p $l);
+            if [[ $x ]]; then echo "$x"; else echo $l; fi;
+        done
+}
+
+netnsvpn() {
     # manually run vpn so it stays within a network namespace,
     # until I get it all wired up with systemd.
     newns vpn start
@@ -1201,10 +1244,27 @@ vc() {
         fi
     fi
     $vpn_on || s ip netns exec vpn /usr/sbin/openvpn --daemon ovpn --config /etc/openvpn/client.conf --cd /etc/openvpn --writepid /run/openvpn/client.pid
+}
+
+
+vc() {
+    [[ $1 ]] || { e "$0: error, expected cmd to run"; return 1; }
     gksudo -- ip netns exec vpn gksudo -u ${SUDO_USER:-$USER} "$@"
 }
 
+transmission-stop() {
+    local pid=$(cat /var/lib/transmission-daemon/transmission-daemon.pid)
+    if [[ $pid ]]; then
+        sudo kill $pid
+    else
+        psg transmission-daemon
+    fi
+}
+
+
+
 transmission() {
+    netnsvpn
     vc transmission-gtk&
     i=0
     while true; do
@@ -1402,10 +1462,11 @@ if [[ $- == *i* ]]; then
 
     prompt_command() {
         local return=$? # this MUST COME FIRST
-        local psc pst
-        local ps_char ps_color
+        local psc pst ps_char ps_color stale_subvol
         unset IFS
         history -a # save history
+
+        # for titlebar
         if [[ ! $DESKTOP_SESSION == xmonad && $TERM == *(screen*|xterm*|rxvt*) ]]; then
             # from the screen man page
             if [[ $TERM == screen* ]]; then
@@ -1416,6 +1477,7 @@ if [[ $- == *i* ]]; then
            echo -ne "$title_escape${PWD/#$HOME/~}  $USER@$HOSTNAME\007"
        fi
 
+
         case $return in
            0) ps_color="$(get_term_color blue)"
                ps_char='\$'
@@ -1434,6 +1496,11 @@ if [[ $- == *i* ]]; then
                ps_color="$(get_term_color bold green)"
             fi
         fi
+        # I would set nullglob, but bash has had bugs where that
+        # doesn't work if not in top level.
+        if [[ -e /nocow/btrfs-stale ]] && ((`ls -AUq /nocow/btrfs-stale|wc -l`)); then
+            ps_char="! $ps_char"
+        fi
         PS1="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
         # emacs completion doesn't like the git prompt atm, so disabling it.
         #PS1="${PS1%"${PS1#*[wW]}"}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "