lots of fixes and improvements
[distro-setup] / brc
diff --git a/brc b/brc
index 382b3627ded5e67a98c6c9fa71fbca675151e9b4..ca9a78682a4d3ee5dd53c98abb2c246894be0949 100644 (file)
--- a/brc
+++ b/brc
@@ -295,6 +295,14 @@ a() {
 
 ack() { ack-grep "$@"; }
 
+anki() {
+    if which anki &>/dev/null; then
+        command anki
+    else
+        schroot -c anki -- anki
+    fi
+}
+
 astudio() {
     # googling android emulator libGL error: failed to load driver: r600
     # lead to http://stackoverflow.com/a/36625175/14456
@@ -314,6 +322,10 @@ bkrun() {
 
 bfg() { java -jar /a/opt/bfg-1.12.14.jar "$@"; }
 
+bigclock() {
+    xclock -digital -update 1 -face 'arial black-80:bold'
+}
+
 btc() {
     local f=/etc/bitcoin/bitcoin.conf
     # importprivkey will timeout if using the default of 15 mins.
@@ -321,7 +333,7 @@ btc() {
     bitcoin-cli -rpcclienttimeout=60000 -$(s grep rpcuser= $f) -$(s grep rpcpassword= $f) "$@"
 }
 
-btcusd() {
+btcusd() { # $1 btc in usd
     local price
     price="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
     printf "$%s\n" "$price"
@@ -329,7 +341,7 @@ btcusd() {
         printf "$%.2f\n" "$(echo "scale=4; $price * $1"| bc -l)"
     fi
 }
-usdbtc() {
+usdbtc() { # $1 usd in btc
     local price
     price="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
     printf "$%s\n" "$price"
@@ -338,7 +350,7 @@ usdbtc() {
         printf "%.8f btc\n" "$(echo "scale=10; $1 / $price "| bc -l)"
     fi
 }
-satoshi() {
+satoshi() { # $1 satoshi in usd
     local price
     price="$(curl -s https://api.coinbase.com/v2/prices/BTC-USD/spot | jq -r .data.amount)"
     price=$(echo "scale=10; $price * 0.00000001"| bc -l)
@@ -438,7 +450,13 @@ cl() {
 }
 
 chrome() {
-    CHROMIUM_FLAGS='--enable-remote-extensions' chromium &r
+    if type -p chromium &>/dev/null; then
+        cmd=chromium
+    else
+        cd
+        cmd="schroot -c stretch chromium"
+        CHROMIUM_FLAGS='--enable-remote-extensions' $cmd &r
+    fi
 }
 
 d() { builtin bg; }
@@ -539,7 +557,10 @@ faf() { # find all files
          -o -name .undo-tree-history -prune \) 2>/dev/null
 }
 
-fastboot() { /a/opt/androidsdk/platform-tools/fastboot "$@"; }
+# one that comes with distros is too old for newer devices
+fastboot() {
+    /a/opt/android-platform-tools/fastboot "$@";
+}
 
 
 # List of apps to install/update
@@ -795,6 +816,10 @@ and works in older versions of git which did not have that."
     echo "${p%%/.git}"
 }
 
+gitian() {
+    git config user.email ian@iankelling.org
+}
+
 gmacs() {
     # quit will prompt if the program crashes.
     gdb -ex=r -ex=quit --args emacs "$@"; r;
@@ -1012,6 +1037,11 @@ mbdisable() {
     set +x
 }
 
+mdt() {
+    markdown -o /tmp/mdtest.html "$1"
+    firefox /tmp/mdtest.html
+}
+
 
 mkc() {
     mkdir "$1"
@@ -1026,11 +1056,13 @@ mkt() { # mkdir and touch file
 
 mkdir() { command mkdir -p "$@"; }
 
+mo() { xset dpms force off; } # monitor off
+
 otp() {
-    echo "oathtool --totp -b"
-    oathtool --totp -b "$@"
+    oathtool --totp -b "$@" | xclip -selection clipboard
 }
 
+# pithosfly is broken due to bitrot.
 pithos() {
     cd /
     export PYTHONPATH=/a/opt/Pithosfly
@@ -1276,7 +1308,7 @@ ser() {
 
 sgo() { # service go
     service=$1
-    ser restart $service
+    ser restart $service || return 1
     if type -p systemctl &>/dev/null; then
         ser enable $service
     fi
@@ -1378,6 +1410,15 @@ srun() {
 sss() { # ssh solo
     ssh -oControlMaster=no -oControlPath=/ "$@"
 }
+ssk() {
+    local -a opts=()
+    while [[ $1 == -* ]]; do
+        opts+=("$1")
+        shift
+    done
+    m pkill -f "^ssh: /tmp/ssh_mux_${USER}_${1#*@}_22_"
+    m ssh "${opts[@]}" "$@"
+}
 
 swap() {
     local tmp
@@ -1553,7 +1594,7 @@ m() { printf "%s\n" "$*";  "$@"; }
 
 
 vpncmd() {
-    m s nsenter -t $(pgrep -f "/usr/sbin/openvpn --suppress-timestamps --nobind --config /etc/openvpn/client/client.conf") -n -m "$@"
+    m s nsenter -t $(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/client/client.conf") -n -m "$@"
 }
 vpnf() {
     vpncmd gksudo -u ian "firefox -no-remote -P firefox-main-profile" &r
@@ -1590,9 +1631,15 @@ vmunshare() {
 
 
 vpn() {
+    if [[ -e /lib/systemd/system/openvpn-client@.service ]]; then
+        local vpn_service=openvpn-client
+    else
+        local vpn_service=openvpn
+    fi
+
     [[ $1 ]] || { echo need arg; return 1; }
-    journalctl --unit=openvpn-client@$1 -f -n0 &
-    s systemctl start openvpn-client@$1
+    journalctl --unit=$vpn_service@$1 -f -n0 &
+    s systemctl start $vpn_service@$1
     # sometimes the ask-password agent does not work and needs a delay.
     sleep .5
     # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779240
@@ -1603,7 +1650,12 @@ vpn() {
 
 vpnoff() {
     [[ $1 ]] || { echo need arg; return 1; }
-    s systemctl stop openvpn-client@$1
+    if [[ -e /lib/systemd/system/openvpn-client@.service ]]; then
+        local vpn_service=openvpn-client
+    else
+        local vpn_service=openvpn
+    fi
+    s systemctl stop $vpn_service@$1
 }
 
 
@@ -1626,6 +1678,7 @@ wtr() { curl wttr.in/boston; }
 xl() {
     # this succeeds even if gnome-screensaver isn\'t running.
     gnome-screensaver-command --exit &>/dev/null
+    mate-screensaver-command --exit &>/dev/null
     if ! pidof xscreensaver; then
         pushd /
         xscreensaver &