intermediate commit
[distro-setup] / .bashrc
diff --git a/.bashrc b/.bashrc
index a3dd3892f88b70f60a2ddfb97e84c231b778accf..d63c6bd6d663075bf3918cab547725d1a18f5acf 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -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; }
@@ -513,7 +520,7 @@ faf() { # find all files
     find $@ -type f
 }
 
-fastboot() { /home/ian/Android/Sdk/platform-tools/fastboot "$@"; }
+fastboot() { /a/opt/androidsdk/platform-tools/fastboot "$@"; }
 
 ff() {
     if type -P firefox &>/dev/null; then
@@ -742,6 +749,9 @@ ic() {
     git commit -am "$*"
 }
 
+idea() {
+    /a/opt/idea-IC-163.7743.44/bin/idea.sh "$@" &r
+}
 
 ifn() {
     # insensitive find
@@ -781,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
@@ -836,7 +850,8 @@ mkc() {
 mkdir() { command mkdir -p "$@"; }
 
 pithos() {
-    cd /a/opt/Pithosfly/
+    cd /
+    export PYTHONPATH=/a/opt/Pithosfly
     python3 -m pithos&r
 }
 
@@ -893,6 +908,9 @@ whatismyip() { pubip; }
 
 
 pwgen() {
+    # -m = min length
+    # -x = max length
+    # -t = print pronunciation
     apg -m 12 -x 16 -t
 }
 
@@ -1074,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
@@ -1192,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
@@ -1208,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
@@ -1409,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
@@ -1423,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='\$'
@@ -1441,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)\] "