dot

packages and services management
Log | Files | Refs | README

commit c732d2e1f945f6889ed6a14249aec6917e8c8e54
parent acf840d1efa154ae0640c3497fa41bb3013c6724
Author: josuah <mail@josuah.net>
Date:   Fri, 18 Nov 2016 00:31:52 -0500

Simplified workflow

Diffstat:
Abin/buffer | 189+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dbin/buffers | 185-------------------------------------------------------------------------------
Mbin/status | 156++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Dbin/status-line | 97-------------------------------------------------------------------------------
Mgit/projects | 1+
Mshell/.profile | 27+++++++++++++++++++++------
Mtmux/.tmux.conf | 2++
Mxorg/.xinitrc | 5++---
8 files changed, 345 insertions(+), 317 deletions(-)

diff --git a/bin/buffer b/bin/buffer @@ -0,0 +1,189 @@ +# ---. ,-- ,-- +# |__/ , , |- |- ,--. .,-- ,--- +# | \ | | | | |--' | `--. +# ---' `--` ' ' `--' ' ---' 2016-11-03 +#------------------------------------------------------------------------------- +# Manage abduco sessions like buffers. + +# External: stest (dmenu), iomenu, abduco +# Busybox: mkdir, sort, tr, sed, exec + + +HELP=' +Usage: buffers COMMAND + +COMMAND + r[run] [command] Run command in an abduco session + a[ttach] Interactively prompt buffer to attach, display. +' +CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/dmenu_run" +COMMAND="$2" +NL=' +' TAB=' ' + + +# +# Update the cache and get the command to run. +# +update_cache() +{ + mkdir -p "${CACHE%/*}" + + # get the command name from cache or stest + IFS=':' + if stest -dqr -n "$CACHE" $PATH + then + stest -flx $PATH | sort -u > "$CACHE" + fi + unset IFS +} + + +# +# Prompt for a file path. +# +get_path() +{ + local type="$1" + + find "$HOME/" -type "$type" ! -path '*/.git/*' ! -name '.git' | + while IFS='' read -r path + do + printf '~%s\n' "${path#$HOME}" + done | + iomenu -l 256 | { + IFS='' read -r path + printf '%s/%s' "$HOME" "${path#'~'}" + } +} + + +# +# Build the name out of the path and set terminal name +# +get_name() +{ + local name="$1" path="${2:+$(cd "$2"; pwd)}" + + [ "$path" ] && name="$name ${path:+~${path#$HOME}}" + + # set terminal's name + printf '\033]0;%s\007' "$name" 1>&2 + + # return the result without forbidden characters + printf %s "$name" | tr / ! +} + +# +# Get the options according to the command and run it +# +run() +{ + local command="${1:-$(iomenu -l 256 < $CACHE)}" options path + + case "$command" in + + # empty command + '' ) + exit 1 + ;; + + # customs options + mbsync ) + options='-a' + ;; + alsamixer ) + options='-c 1' + ;; + mail | mailx | s-nail | music | iirc ) + options='' + ;; + + # single-buffer editor + vi | vis | less | ex-vi | ex | ed ) + path="$(get_path f)" + options="$path" + ;; + + # multi-buffer editor + vim ) + path="$(get_path d)" + cd "$path" + ;; + + # else, prompt for command + * ) + read -p "$command> " options + + if [ -z "${options##*\**}" -a "$options" ] + then + path="$(get_path f)" + options="${options##*\*} $path ${options%%\**}" + fi + ;; + esac + + name="$(get_name "$command" "$path")" + + # run new or existing abduco session with this name + TERM='screen' ABDUCO="$command" exec abduco -e '^z' -A "$name" \ + $command $options +} + + +# +# Attach to an existing abduco session. +# +attach() +{ + local name + + # if already on a session, print its name and exit + if [ "$ABDUCO" ] + then + printf '[ %s ]\n' "$ABDUCO" | tr ! / + exit 1 + fi + + # overwrite the prompt + printf '\033[A' + + # get the session name by prompting the user + name="$( + abduco | + tr ! / | + sed -r '1d; s/(.*)\t(.*)/\2 # \1/' | + iomenu -s '#' -l 8 | + tr / ! + )" + + # set the name of the terminal. + printf '\033]0;%s\007' "$name" | tr ! / + + # attach to the session. + if [ "$name" ] + then + TERM='screen' ABDUCO="$name" exec abduco -e '^z' -a "$name" + fi +} + + +main() +{ + # parse the arguments + case "$1" in + r | run ) + update_cache + run "$2" + ;; + a | attach ) + attach + ;; + * ) + printf '%s\n' "$help" + exit 0 + ;; + esac +} + +main $@ diff --git a/bin/buffers b/bin/buffers @@ -1,185 +0,0 @@ -# ---. ,-- ,-- -# |__/ , , |- |- ,--. .,-- ,--- -# | \ | | | | |--' | `--. -# ---' `--` ' ' `--' ' ---' 2016-11-03 -#------------------------------------------------------------------------------- -# Manage abduco sessions like buffers. - -# External: stest (dmenu), iomenu, abduco -# Busybox: mkdir, sort, tr, sed, exec - - -HELP=' -Usage: buffers COMMAND - -COMMAND - r[run] [command] Run command in an abduco session - a[ttach] Interactively prompt buffer to attach, display. -' -CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/dmenu_run" -COMMAND="$2" -NL=' -' TAB=' ' - - -# -# Update the cache and get the command to run. -# -update_cache() -{ - mkdir -p "${CACHE%/*}" - - # get the command name from cache or stest - IFS=':' - if stest -dqr -n "$CACHE" $PATH - then - stest -flx $PATH | sort -u > "$CACHE" - fi - unset IFS -} - - -# -# Prompt for a file path. -# -get_path() -{ - local type="$1" - - find "$HOME/" -type "$type" ! -path '*/.git/*' ! -name '.git' | - while IFS='' read -r path - do - printf '~%s\n' "${path#$HOME}" - done | - iomenu -l 256 | { - IFS='' read -r path - printf '%s/%s' "$HOME" "${path#'~'}" - } -} - - -# -# Build the name out of the path and set terminal name -# -get_name() -{ - local name="$1" path="${2:+$(cd "$2"; pwd)}" - - [ "$path" ] && name="$name ${path:+~${path#$HOME}}" - - # set terminal's name - printf '\033]0;%s\007' "$name" 1>&2 - - # return the result without forbidden characters - printf %s "$name" | tr / ! -} - -# -# -# Get the options according to the command and run it -# -run() -{ - local command="${1:-$(iomenu -l 256 < $CACHE)}" options path - - case "$command" in - - # empty command - '' ) - exit 1 - ;; - - # customs options - mbsync ) - options='-a' - ;; - alsamixer ) - options='-c 1' - ;; - mail | mailx | s-nail | music | iirc ) - options='' - ;; - - # single-buffer editor - vi | vis | less | ex-vi | ex | ed ) - path="$(get_path f)" - options="$path" - ;; - - # multi-buffer editor - vim ) - path="$(get_path d)" - cd "$path" - ;; - - # else, prompt for command - * ) - read -p "$command> " options - - if [ -z "${options##*\**}" -a "$options" ] - then - path="$(get_path f)" - options="${options##*\*} $path ${options%%\**}" - fi - ;; - esac - - name="$(get_name "$command" "$path")" - - # run new or existing abduco session with this name - TERM='screen' ABDUCO="$command" exec abduco -e '^z' -A "$name" \ - $command $options -} - - -# -# Attach to an existing abduco session. -# -attach() -{ - local name - - # if already on a session, print its name and exit - if [ "$ABDUCO" ] - then - printf '[ %s ]\n' "$ABDUCO" | tr ! / - exit 1 - fi - - # overwrite the prompt - printf '\033[A' - - # get the session name by prompting the user - name="$(abduco | tr ! / | sed -r '1d; s/(.*)\t(.*)/\2 # \1/' | sort | - iomenu -s '#' -l 8 | tr / !)" - - # set the name of the terminal. - printf '\033]0;%s\007' "$name" | tr ! / - - # attach to the session. - if [ "$name" ] - then - TERM='screen' ABDUCO="$name" exec abduco -e '^z' -a "$name" - fi -} - - -main() -{ - # parse the arguments - case "$1" in - r | run ) - update_cache - run "$2" - ;; - a | attach ) - attach - ;; - * ) - printf '%s\n' "$help" - exit 0 - ;; - esac -} - -main $@ diff --git a/bin/status b/bin/status @@ -6,46 +6,150 @@ # Plain text status line for wherever useful -if [ -d $MAIL/new ] -then - mail="$(ls "$MAIL/new" | wc -l)" - mail="${mail#0}" - mail="${mail:+mail $mail}" -fi +STATUS="$HOME/.cache/status" +[ -f "$STATUS/pwd" ] && IFS='' read -r SHELL_PWD < $STATUS/pwd +SEPARATOR=' | ' +START=' ' +STOP=' ' -date="$(date +'%Y-%m-%d %H:%M')" +# +# Current directory git status, +# +status_path() +{ + cd $SHELL_PWD -cpu="$(awk '/cpu/ { - usage = ($2 + $4) / ($2 + $4 + $5) * 100; + local pwd="$(pwd)" + + if [ -z "${pwd##$HOME*}" ] + then + printf '~%s' "${pwd#$HOME}" + fi + + git rev-parse &>/dev/null || return 0 + + git status --porcelain -b | awk ' + + /^## / { + branch = $0; + sub(/^##/, "", branch); + sub(/\.\.\..*/, "", branch); + + if ($0 ~ /ahead /) { + ahead = $0; + sub(/.*ahead /, "", ahead); + sub(/\].*|, .*/, "", ahead); + } + + if ($0 ~ /behind /) { + behind = $0; + sub(/.*behind /, "", behind); + sub(/\].*|, .*/, "", behind); + } + + m = 1; + } + + m == 0 && /^\?\? / { untracked++; m = 1; } + m == 0 && /^U. / { conflicts++; m = 1; } + m == 0 && /^.U / { conflicts++; m = 1; } + m == 0 && /^DD / { conflicts++; m = 1; } + m == 0 && /^AA / { conflicts++; m = 1; } + m == 0 && /^.M / { changed++; } + m == 0 && /^.D / { changed++; } + m == 0 && /^[^ ]. / { staged++; } + m == 1 { m = 0; } + + END { + printf("%s", branch); + + if (untracked + conflicts + changed + staged + behind + ahead \ + == 0) { + printf " ok"; + } else { + if (untracked) printf " ?%d", untracked; + if (conflicts) printf " !%d", conflicts; + if (changed ) printf " +%d", changed ; + if (staged ) printf " *%d", staged ; + if (behind ) printf " ↓%d", behind ; + if (ahead ) printf " ↑%d", ahead ; + } + }' } -END { - printf("%i", usage); -}' /proc/stat)" -battery="$( - find -L /sys/class/power_supply -maxdepth 2 -name capacity 2> /dev/null -)" -if [ -f "$battery" ] -then - IFS='' read -r battery < "$battery" - battery="bat $battery%" -fi +# +# Maildir format, just file count in "$MAIL/new" +# +status_mail() +{ + local mail + if [ -d "$MAIL/new" ] + then + mail="$(ls "$MAIL/new" | wc -l)" + mail="${mail#0}" + mail="${mail:+mail $mail}" + + printf %s "$mail" + fi +} + + +status_date() +{ + date +'%Y-%m-%d %H:%M' +} -main() { - printf ' ' + +# +# Seriously, now that I understood how load average works, I will never +# ever want to look at any CPU percentage usage. Just use /proc/loadavg +# +status_cpu() +{ + read latest_1 latest_5 latest_15 trailing < /proc/loadavg + + printf '%s %s %s' "$latest_1" "$latest_5" "$latest_15" +} + + +status_battery() +{ + local battery="$( + find -L /sys/class/power_supply -maxdepth 2 -name capacity \ + 2> /dev/null + )" + + if [ -f "$battery" ] + then + IFS='' read -r battery < "$battery" + printf 'bat %d%%' "$battery" + fi +} + + +main() +{ + local segment + + mkdir -p "$STATUS" + + printf "$START" while [ "$#" -gt 0 ] do - printf '%s' "$1" + segment="$(status_$1)" + + printf %s "$segment" - [ "$1" -a "$#" -gt 1 ] && printf ' | ' + [ "$segment" -a "$#" -gt 1 ] && printf "$SEPARATOR" shift done - printf ' ' + printf "$STOP" } -main "$mail" "cpu $cpu%" "$battery" "$date" + +main ${@:-path mail cpu battery date} diff --git a/bin/status-line b/bin/status-line @@ -1,97 +0,0 @@ -# ,--. | | , * -# `. |-- ,--. |-- , , ,--- | , ---. ,--. -# `. | ,--| | | | `--. | | | | |--' -# `--' ' `--` ' `--` ---' '--- ' ' ' `--' 2016-11-02 -#------------------------------------------------------------------------------- -# -# Display a status line at the top of the terminal window. -# -# This can be put in the prompt to update the status line at every prompt: -# -# PS1='$(status_line)> ' - - -# -# Current directory git status, -# -git_status() -{ - git rev-parse &>/dev/null || return 0 - - git status --porcelain -b | awk ' - - /^## / { - branch = $0; - sub(/^##/, "", branch); - sub(/\.\.\..*/, "", branch); - - if ($0 ~ /ahead /) { - ahead = $0; - sub(/.*ahead /, "", ahead); - sub(/\].*|, .*/, "", ahead); - } - - if ($0 ~ /behind /) { - behind = $0; - sub(/.*behind /, "", behind); - sub(/\].*|, .*/, "", behind); - } - - m = 1; - } - - m == 0 && /^\?\? / { untracked++; m = 1; } - m == 0 && /^U. / { conflicts++; m = 1; } - m == 0 && /^.U / { conflicts++; m = 1; } - m == 0 && /^DD / { conflicts++; m = 1; } - m == 0 && /^AA / { conflicts++; m = 1; } - m == 0 && /^.M / { changed++; } - m == 0 && /^.D / { changed++; } - m == 0 && /^[^ ]. / { staged++; } - m == 1 { m = 0; } - - END { - printf("\033[1m%s", branch); - - if (untracked + conflicts + changed + staged + behind + ahead \ - == 0) { - printf " \033[32m✔"; - } else { - if (untracked) printf " \033[34m?\033[37m%d", untracked; - if (conflicts) printf " \033[31m!\033[37m%d", conflicts; - if (changed ) printf " \033[32m+\033[37m%d", changed ; - if (staged ) printf " \033[33m*\033[37m%d", staged ; - if (behind ) printf " \033[36m↓\033[37m%d", behind ; - if (ahead ) printf " \033[36m↑\033[37m%d", ahead ; - } - - printf "\033[0m"; - }' -} - - -main() -{ - local pwd="$(pwd)" - [ -z "${pwd##$HOME*}" ] && pwd="~${pwd#$HOME}" - - local status="$(status)" - - local col="$(stty size)" - col="$((${col#* } - ${#status} - 1))" - - printf '\n\033[s\033[0;0H\033[K' - - # right part - printf '\033[%sC%s\r' "$col" "$status" - - # left part - printf ' %s %s' "$pwd" "$(git_status)" - - # terminal name - printf '\033]0;%s %s\007' "$pwd" - - printf '\n\033[K\033[u\033[A' -} - -main $@ diff --git a/git/projects b/git/projects @@ -8,3 +8,4 @@ http://github.com/josuah/vis http://github.com/josuah/fungus-vs-pathogen http://github.com/josuah/miniwi http://github.com/josuah/drawille +http://github.com/josuah/ii diff --git a/shell/.profile b/shell/.profile @@ -29,8 +29,23 @@ export DVTM_EDITOR="$PAGER" export PS1='$( [ "$?" -eq 0 ] && color=32 || color=31 - # status - status-line + # update pwd + printf "%s\n" "$(pwd)" > $HOME/.cache/status/pwd + + # status line + status="$(status)" + + # left padding + col="$(stty size)" col="$((${col#* } - ${#status} - 1))" + + # print status line + printf "\n\033[s\033[0;0H\033[K\033[%sC%s" "$col" "$status" + + # clear one line and reset cursor position + printf "\n\033[K\033[u\033[A" + + # terminal name + printf "\033]0;shell\007" # cursor shape printf "\033[?6c" @@ -47,10 +62,10 @@ alias ll='l -lh' alias la='l -A' alias lla='l -Alh' alias p='$PAGER' -alias a='buffers attach' -alias r='buffers run' -alias v='buffers run $VISUAL' -alias s='buffers run $SHELL' +alias a='buffer attach' +alias r='buffer run' +alias v='buffer run $VISUAL' +alias s='buffer run $SHELL' alias t='tmux attach &>/dev/null || tmux new' alias f='find . -type f ! -path "*/.git/*" | sed "s/^\\.\\///" | iomenu' alias d='find . -type d ! -path "*/.git/*" | sed "s/^\\.\\///" | iomenu' diff --git a/tmux/.tmux.conf b/tmux/.tmux.conf @@ -94,6 +94,8 @@ set -g mode-style bg=white,fg=black # STATUS +set -g status-interval 5 + # Global set -g status-position top set -g status-justify left diff --git a/xorg/.xinitrc b/xorg/.xinitrc @@ -3,10 +3,9 @@ setxkbmap -layout us -option compose:ralt -variant dvorak feh --bg-fill ~/Images/interstellar-2.png -while true +while xsetroot -name "$(status)" do - xsetroot -name "$(status)" - sleep 10 + sleep 4 done & nm-applet & xfce4-power-manager &