+rl() {
+ # rsync, root is required to keep permissions right.
+ # rsync --archive --human-readable --verbose --itemize-changes --checksum \(-ahvic\) \
+ # --no-times --delete
+ # basically, make an exact copy, use checksums instead of file times to be more accurate
+ rsync -ahvic --delete "$@"
+}
+rld() {
+ # like rlu, but don't delete files on the target end which
+ # do not exist on the original end.
+ rsync -ahvic "$@"
+}
+complete -F _rsync -o nospace rld rl rlt
+
+rlt() {
+ # rl without preserving modification time.
+ rsync -ahvic --delete --no-t "$@"
+}
+
+rlu() { # [OPTS] HOST PATH
+ # 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
+ path="${@:$#}" # last
+ host="${@:$#-1:1}" # last -1
+ # rync here uses checksum instead of time so we don't mess with
+ # unison relying on time as much. g is for group, same reason
+ # to keep up with unison.
+ s rsync -rlpchviog --relative "${opts[@]}" "$path" "root@$host:/";
+}
+
+
+rspicy() { # HOST DOMAIN
+ local port=$(ssh $1<<EOF
+sudo virsh dumpxml $2|grep "<graphics.*type='spice'" | \
+ sed -rn "s/.*port='([0-9]+).*/\1/p"
+EOF
+ )
+ if [[ $port ]]; then
+ spicy -h $1 -p $port
+ else
+ echo "error: no port found. check that the domain is running."
+ fi
+}
+
+s() {
+ # background
+ # alias s='SUDOD="$PWD" sudo -i '
+ # because this is an alias, and the extra space at the end, it would allow
+ # aliases to be used with it. but aliases aren't used in scripts,
+ # better to eliminate inconsistencies. Plus, you can't do s=s; $s command
+ # with an alias, which I like to do in some functions
+ # extra space at the end allows aliases to work
+ #
+ # note: gksudo is recommended for X apps because it does not set the
+ # home directory to the same, and thus apps writing to ~ fuck things up
+ # with root owned files.
+ #
+ if [[ $EUID != 0 || $1 == -* ]]; then
+ SUDOD="$PWD" sudo -i "$@"
+ else
+ "$@"
+ fi
+}
+
+safe_rename() {
+ if [[ $# != 2 ]]; then
+ echo safe_rename error: $# args, need 2 >2
+ return 1
+ elif [[ $1 != $2 ]]; then
+ if [[ -e $2 ]]; then
+ echo Cannot rename "$1" to "$2" as it already exists.
+ else
+ mv "$1" "$2"
+ fi
+ fi
+}
+
+sdf() {
+ c /sdx/test/sandbox/
+}
+
+ser() {
+ local s; [[ $EUID != 0 ]] && s=sudo
+ if type -p systemctl &>/dev/null; then
+ $s systemctl $1 $2
+ else
+ $s service $2 $1
+ fi
+}
+
+sgo() { # service go
+ service=$1
+ ser restart $service
+ if type -p systemctl &>/dev/null; then
+ ser enable $service
+ fi
+}
+
+
+shellck() {
+ # 2086 = unquoted $var
+ # 2046 = unquoted $(cmd)
+ # i had -x as an arg, but debian testing(stretch) doesn't support it
+ shellcheck -e 2086,2046,2068,2006,2119 "$@"
+}
+