dot

packages and services management
Log | Files | Refs | README

commit 1e1ae651262c4d296bfb2003c6f5d8d5f9dbd0b8
parent ba3994f61a896bd3a8852402b8e018d52c6c46ca
Author: josuah <mail@josuah.net>
Date:   Sat, 19 Nov 2016 17:46:51 +0100

Now buffer is a _grand_ program

Diffstat:
M.profile | 11++++++-----
M.vim/vimrc | 4----
M.xinitrc | 3+--
Mbin/buffer | 158+++++++++++++++++++++++++++++++++++--------------------------------------------
Mbin/build | 3+--
Mbin/config | 10+++++-----
6 files changed, 82 insertions(+), 107 deletions(-)

diff --git a/.profile b/.profile @@ -33,11 +33,11 @@ export PS1='$( printf "\033[?6c" # status line - printf "\n%$(stty size | cut -d " " -f 2)s\r%s" \ + printf "\n%$(stty size | cut -d " " -f 2)s\r%s\n" \ "$(status)" "$(status path "$PWD")" # prompt character - printf "\033[1;3%sm\n ─── \[\033[0m\]" "$color" + printf "\033[1;3%sm ─── \033[0m" "$color" )' export PS2=' > ' export PS3=' > ' @@ -48,7 +48,7 @@ alias la='ls -AlhF --color' alias p='$PAGER' alias a='buffer' alias b='buffer' -alias v='b $VISUAL' +alias v='b $VISUAL +' alias s='b $SHELL' alias t='tmux attach &>/dev/null || tmux new' alias f='find . -type f ! -path "*/.git/*" | sed "s/^\\.\\///" | iomenu' @@ -119,8 +119,9 @@ weather() sanitize() { find . -mindepth 1 | tac | while IFS= read -r p - do mv "$p" "${p%/*}/$(printf %s "${p##*/}" \ - | sed 's/[^[:alnum:],._/+-]/_/g' + do + mv "$p" "${p%/*}/$( + printf %s "${p##*/}" | sed 's/[^[:alnum:],._/+-]/_/g' )" done } diff --git a/.vim/vimrc b/.vim/vimrc @@ -53,10 +53,6 @@ nmap <Leader>t :pwd \| echo '' \| tags \| echo ''<CR>:tag<space> nmap <Leader>" : echo '' \| registers <CR> nmap <Leader>' : echo '' \| marks <CR>:' nmap <Leader>m :silent make \| redraw! \| clist<CR> -let find_command = "find -type f ! -path '*/.svn/*' ! -path '*/.git/*' - \\| sed 's/.\\///' - \\| fzy" -nmap <Leader>e :e <C-r>=system(find_command)<CR> \| redraw!<CR> " <c>hange <o>ption <...> nmap col :set list ! \| set list ?<CR> diff --git a/.xinitrc b/.xinitrc @@ -4,10 +4,9 @@ setxkbmap -layout us -option compose:ralt -variant dvorak while xsetroot -name "$(status)" do - sleep 4 + sleep 5 done & -nm-applet & st & exec dwm diff --git a/bin/buffer b/bin/buffer @@ -1,12 +1,11 @@ # ---. ,-- ,-- -# |__/ , , |- |- ,--. .,-- ,--- -# | \ | | | | |--' | `--. -# ---' `--` ' ' `--' ' ---' 2016-11-03 +# |__/ , , |- |- ,--. .,-- +# | \ | | | | |--' | +# ---' `--` ' ' `--' ' 2016-11-16 #------------------------------------------------------------------------------- -# Manage abduco sessions like buffers. - -# External: stest (dmenu), iomenu, abduco -# Busybox: mkdir, sort, tr, sed, exec +# Detacheable buffer for programs and files +# +# External dependencies: stest (dmenu), iomenu, abduco CACHE="${XDG_CACHE_HOME:-$HOME/.cache}" @@ -18,34 +17,27 @@ NL=' # # Update the cache and get the command to run. # -update_cache() +update_commands_cache() { - mkdir -p "$CACHE" - # get the command name from cache or stest IFS=':' if stest -dqr -n "$CACHE/dmenu_run" $PATH then stest -flx $PATH | sort -u > "$CACHE/dmenu_run" + cp "$CACHE/dmenu_run" "$CACHE/buffer/run" fi unset IFS - - # populate iomenu cache from dmenu's cache - if [ ! -f "$CACHE/iomenu_run" ] - then - cp "$CACHE/dmenu_run" "$CACHE/iomenu_run" - fi } # # Generate descriptions of commands from whatis(1). This takes a lot of time. # -update_descriptions() +update_descriptions_cache() { local whatis - update_cache + update_commands_cache while IFS= read -r command do @@ -53,44 +45,48 @@ update_descriptions() if [ "$whatis" ] then printf '%-20s # %-20s %s\n' \ - "$command" "${whatis% - *}" "${whatis#* - }" + "$command" "${whatis%% - *}" "${whatis#* - }" else printf '%s\n' "$command" fi - done < $CACHE/dmenu_run > "$CACHE/iomenu_run" + done < $CACHE/dmenu_run > "$CACHE/buffer/run" } # -# Prompt for a file path. +# Prompt for options for a given command and log it to an history file # -get_path() +get_options() { - local type="$1" + local command="$1" + local history - 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#'~'}" - } + printf '%s ' "$command" >> "$CACHE/buffer/history" + + while read -r cmd options + do + [ "$command" = "$cmd" -a "$options" ] && printf '%s\n' "$options" + done < $CACHE/buffer/history | + iomenu -c -p "$command" | + tee -a "$CACHE/buffer/history" + + sort -u "$CACHE/buffer/history" -o "$CACHE/buffer/history" + # printf %s "$history" > "$CACHE/buffer/history" } # -# Build the name out of the path and set terminal name +# Prompt for a file path in $HOME and print it. # -get_name() +get_path() { - local name="$1" path="${2:+$(cd "$2"; pwd)}" + printf %s "$HOME" - [ "$path" ] && name="$name ${path:+~${path#$HOME}}" - - # return the result without forbidden characters - printf %s "$name" | tr / ! + find ~ -type f ! -path '*/.cache/*' ! -path '*/.git/*' | + while IFS='' read -r path + do + printf '~%s\n' "${path#$HOME}" + done | iomenu -l 256 | sed 's/^~//' } @@ -99,73 +95,57 @@ get_name() # run() { - local command="${*:-$( + local command="$1" options="" + local path name + + [ $# -gt 0 ] && shift && options="$*" + + command="${command:-$( iomenu -l 256 -s '#' << EOF | tr / ! +# # $(abduco | tr ! / | sed -r '2,$ s/(.*)\t(.*)/\2 # \1/') +# # Commands -$(cat "$CACHE/iomenu_run") +$(cat "$CACHE/buffer/run") EOF - )}" options path - - case "$command" in - - # empty command - '' ) - exit 1 - ;; - - # customs options - mbsync ) - options='-a' - ;; - alsamixer ) - options='-c 1' - ;; - mail | mailx | s-nail | music | iirc | 'vim '*) - 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" ] + )}" + + [ -z "$command" ] && exit 1 + + # if there is not already arguments in the command, prompt for them + if [ "${command##* *}" ] + then + [ -z "$options" ] && options="$( get_options "$command")" + + # if '+' is at the end of the options then prompt for a path + if [ -z "${options%%*+}" -a "$options" ] then - path="$(get_path f)" - options="${options##*\*} $path ${options%%\**}" + path="$(get_path)" options="${options%+}" fi - ;; - esac + fi - name="$(get_name "$command" "$path")" + name="$command${options:+ $options}${path:+ ~${path#$HOME}}" + name="$(printf %s "$name" | tr / !)" - # run new or existing abduco session with this name - TERM='screen' ABDUCO="$command" exec abduco -e '^z' -A "$name" \ - $command $options + # run new or existing session with this name + TERM='screen' ABDUCO="$command" exec abduco -e ^Z -A "$name" \ + $command $options "$path" } main() { - if [ "$1" = '-u' ] + mkdir -p "$CACHE/buffer" + + if [ "$1" = -u ] then - update_descriptions + update_descriptions_cache else - update_cache + update_commands_cache run $@ fi + + stty sane } main $@ diff --git a/bin/build b/bin/build @@ -72,14 +72,13 @@ compile() { local name="$1" tar="$2" local PREFIX="$PROGRAMS/$name" - local dirs='bin doc etc include lib libexec man share' [ ! -f "$CONFIG/build/$name" ] && error "$2 has no build script" . "$CONFIG/build/$name" info "Installing $name" - cd "$PREFIX" && mkdir -p $dirs + cd "$PREFIX" && mkdir -p bin doc etc include lib libexec man share cd src && build "$name" cd "$PREFIX" && rmdir -p --ignore-fail-on-non-empty * } diff --git a/bin/config b/bin/config @@ -37,7 +37,7 @@ link() } -git-repos() +git_repos() { local projects="$HOME/Projects" @@ -48,7 +48,7 @@ git-repos() do [ "${dir}" ] && mkdir -p "${dir%/*}" printf 'cloning %s\n' "${url##*/}" - nohup git clone -q "$url" $dir 2> /dev/null & + git clone -q "$url" "$dir" 2> /dev/null & done < ~/.config/git/projects printf 'still running in the background' @@ -69,7 +69,7 @@ netrc() } -vim-plugins() +vim_plugins() { local bundle=~/.vim/bundle @@ -95,9 +95,9 @@ main() case "$1" in l ) link ;; - g ) git-repos ;; + g ) git_repos ;; m ) netrc ;; - v ) vim-plugins ;; + v ) vim_plugins ;; * ) usage ;; esac }