various fixes
authorIan Kelling <ian@iankelling.org>
Sat, 27 Aug 2016 19:41:33 +0000 (12:41 -0700)
committerIan Kelling <ian@iankelling.org>
Thu, 4 May 2017 23:42:08 +0000 (16:42 -0700)
.bashrc
README

diff --git a/.bashrc b/.bashrc
index 3dc94d42688bc01d40cbb2a3f6fb9c9de4fbc8b5..912b678aac9c76bb8e67408ce6436125af0cc70b 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -210,15 +210,14 @@ C_DEFAULT_DIR=/a
 ## include files ###
 ###################
 
-for _x in /a/bin/distro-functions/src/* /a/bin/*/*-function?(s); do
+for _x in /a/bin/distro-functions/src/* /a/bin/!(githtml)/*-function?(s); do
     source "$_x"
 done
 unset _x
 # so I can share my bashrc
-for x in /a/bin/bash_unpublished/*; do source $x; done
+for x in /a/bin/bash_unpublished/!(.#*); do source $x; done
 source $(dirname $(readlink -f $BASH_SOURCE))/path_add-function
 source /a/bin/log-quiet/logq-function
-source /a/bin/log-quiet/log-once-function
 path_add /a/exe
 path_add --ifexists --end /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools
 # todo, these need to be renamed to be less generic.
@@ -579,6 +578,9 @@ rename-test() {
     return 0
 }
 
+feh() {
+    command feh -FzZ "$@"
+}
 
 funce() {
     # like -e for functions. returns on error.
@@ -629,14 +631,25 @@ git_empty_branch() { # start an empty git branch. carefull, it deletes untracked
     git clean -fdx
 }
 
+gitroot() {
+    local help="Usage: gitroot [--help]
+Print the full path to the root of the current git repo
+
+Handles being within a .git directory, unlike git rev-parse --show-toplevel,
+and works in older versions of git which did not have that."
+    if [[ $1 == --help ]]; then
+        echo "$help"
+        return
+    fi
+    local p=$(git rev-parse --git-dir) || { echo "error: not in a git repo" ; return 1; }
+    [[ $p != /* ]] && p=$PWD
+    echo "${p%%/.git}"
+}
+
 gr() {
     grep -iIP --color=auto "$@"
 }
 
-
-
-
-
 grr() {
     if [[ ${#@} == 1 ]]; then
         grep -riIP --color=auto "$@" .
@@ -842,7 +855,7 @@ whatismyip() { pubip; }
 
 
 pwgen() {
-    apg -s -m 10 -x 14 -t
+    apg -m 12 -x 16 -t
 }
 
 
@@ -891,7 +904,8 @@ rlu() { # [OPTS] HOST PATH
 }
 
 
-rspicy() { # HOST DOMAIN
+rspicy() { # usage: HOST DOMAIN
+    # connect to spice vm remote host. use vspicy for local host
     local port=$(ssh $1<<EOF
 sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
        sed -rn "s/.*port='([0-9]+).*/\1/p"
@@ -1019,8 +1033,12 @@ t() {
     local x
     local -a args
     if type -t trash-put >/dev/null; then
-        # skip args that don't exist, or else it's an err
-        for x in "$@"; do [[ ! -e $x ]] || args+=("$x"); done
+        # skip args that don't exist, or else trash-put will have an error
+        for x in "$@"; do
+            if [[ -e $x || -L $x ]]; then
+                args+=("$x")
+            fi
+        done
         [[ ! ${args[@]} ]] || trash-put "${args[@]}"
     else
         rm -rf "$@"
@@ -1135,12 +1153,16 @@ vc() {
     # until I get it all wired up with systemd.
     newns vpn start
     pid=$(< /run/openvpn/client.pid)
-    if [[ ! $pid ]]; then
-        s ip netns exec vpn /usr/sbin/openvpn --daemon ovpn --config /etc/openvpn/client.conf --cd /etc/openvpn --writepid /run/openvpn/client.pid
-    elif [[ ! -e /proc/$pid ]]; then
-        echo "$0: ERROR: pidfile pid $pid is not a process!!!"
-        return 1
+    vpn_on=false
+    if [[ $pid ]]; then
+        if [[ -e /proc/$pid ]]; then
+            vpn_on=true
+        else
+            vpn_on=false
+            s rm -f /run/openvpn/client.pid
+        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
     gksudo -- ip netns exec vpn gksudo -u ${SUDO_USER:-$USER} "$@"
 }
 
@@ -1155,6 +1177,7 @@ transmission() {
     echo "$0: tun_ip=$tun_ip"
     [[ $tun_ip ]] || { e "$0: error: no tun0 addr found"; return 1; }
     ssh dopub bash <<EOF
+set -e
 rule="-A PREROUTING -i eth0 -p tcp -m tcp --dport 63324 -j DNAT --to-destination $tun_ip:63324"
 found=false
 while read -r line; do
@@ -1210,7 +1233,7 @@ vrm() {
 
 
 
-vspicy() {
+vspicy() { # usage: VIRSH_DOMAIN
     # connect to vms made with virt-install
     spicy -p $(sudo virsh dumpxml "$1"|grep "<graphics.*type='spice'"|\
                    sed -r "s/.*port='([0-9]+).*/\1/")
diff --git a/README b/README
index 443c4c98c5860555a8056d0fcfbd9cbbb46dbb19..1633f7853cc48802d84b461bccfb3c32745cd45c 100644 (file)
--- a/README
+++ b/README
@@ -1,8 +1,8 @@
-Misc configs that I use
+Misc configs & ~1k loc in bashrc
 
 Part of how I run GNU/Linux. I try fully automate my systems and store
 all configs and scripts, except private info at
-https://iankelling.org/git. Other confguration repos are my bashrc and
-emacs config which are kept in good state and have their own repos at
-https://iankelling.org/git/?p=my-bashrc;a=tree and
-https://iankelling.org/git/?p=my-dot-emacs;a=tree.
+https://iankelling.org/git.
+
+Please email me if you have a patches, bugs, feedback, or republish this
+somewhere else: Ian Kelling <ian@iankelling.org>.