dot

packages and services management
Log | Files | Refs | README

commit cf361439e8dbdb3b95dd71b887b5900923499ec3
parent 103692f032b8ac29a77c392b6ed405f298be472e
Author: josuah <mail@josuah.net>
Date:   Tue, 18 Oct 2016 22:45:56 -0400

Updated buffer command.

Diffstat:
ABUILD/fzy | 3+++
Mabduco/config.h | 2+-
Abin/.config/buffers | 10++++++++++
Mbin/buffers | 172+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Mdvtm/config.h | 1-
Mshell/.config/shell/environment | 1+
Mshell/.profile | 24++++++++++++------------
Mvim/.vim/vimrc | 6++----
8 files changed, 145 insertions(+), 74 deletions(-)

diff --git a/BUILD/fzy b/BUILD/fzy @@ -0,0 +1,3 @@ +# A better fuzzy finder + +tar=https://github.com/jhawthorn/fzy/archive/master.tar.gz diff --git a/abduco/config.h b/abduco/config.h @@ -6,7 +6,7 @@ static char KEY_DETACH = CTRL('z'); /* redraw key to send a SIGWINCH signal to underlying process * (set to 0 to disable the redraw key) */ -static char KEY_REDRAW = CTRL('l'); +static char KEY_REDRAW = 0; /* Where to place the "abduco" directory storing all session socket files. * The first directory to succeed is used. */ diff --git a/bin/.config/buffers b/bin/.config/buffers @@ -0,0 +1,10 @@ +mbsync -a +alsamixer -c 1 +ping -c 3 www.wikipedia.org +feeds read +irc -i +htop +s-nail +rirc +agenda +music diff --git a/bin/buffers b/bin/buffers @@ -5,101 +5,161 @@ #------------------------------------------------------------------------------- # Run commands in detachable buffers -# External: stest (dmenu), fzf, abduco +# External: stest (dmenu), fzy, abduco # Busybox: mkdir, tee, sort, clear, tr, sed help=' -NAME - buffers - run commands in detachable buffers - -SYNTAX - buffers COMMAND - -DESCRIPTION - r, run [CMD] - If CMD not specified, ask interactively then run it in an - abduco session - a, attach - Interactively prompt buffer to attach, display. -' -NL=' -' -TAB=' ' +USAGE: buffers COMMAND -case "$1" in -r | run ) - shift; for arg in $@; do cmd="$cmd $arg"; done; cmd="${cmd# }" +COMMAND + r[run] [CMD] Run CMD in an abduco session + a[ttach] Interactively prompt buffer to attach, display. +' NL=' +' TAB=' ' - # Get or create the cache file - cache="${XDG_CACHE_HOME:-"$HOME/.cache"}" - mkdir -p "$cache" - cache="$cache/dmenu_run" - # Update the cathe and get the command - printf '\033[1A' +# FUNCTIONS +#------------------------------------------------------------------------------- + +# +# Run a command with some arguments in an abduco session +# +run() +{ + local cmd="$1" opt path + + # Update the cache and get the command + [ -z "$cmd" ] && cmd="$( - IFS=: - if stest -dqr -n "$cache" $PATH - then stest -flx $PATH | sort -u | tee "$cache" - else tee < "$cache" - fi | fzf + # Get or create the cache file + cache="${XDG_CACHE_HOME:-"$HOME/.cache"}" + mkdir -p "$cache" + cache="$cache/dmenu_run" + + # Overwrite the prompt + printf '\033[1A' 1>&2 + + # Get the command name from cache or stest + if IFS=':' stest -dqr -n "$cache" $PATH + then + stest -flx $PATH | sort -u | tee "$cache" + else + tee < "$cache" + fi | fzy )" # Get command arguments and the session name - name="$cmd" + case "$cmd" in - '' ) exit 1 ;; - mbsync ) opt='-a' ;; - alsamixer ) opt='-c 1' ;; - ping ) opt='-c 3 www.wikipedia.org' ;; - feeds ) opt='read' ;; - irc ) opt='-i' ;; - htop | s-nail | rirc | agenda | music ) : ;; + + # Empty command + '' ) + exit 1 + ;; + + # Customs options + mbsync ) + opt='-a' + ;; + alsamixer ) + opt='-c 1' + ;; + ping ) + opt='-c 3 www.wikipedia.org' + ;; + feeds ) + opt='read' + ;; + irc ) + opt='-i' + ;; + htop | s-nail | rirc | agenda | music ) + opt='' + ;; + + # Single-buffer editor vi | vis | less | ex-vi | ex | ed ) - path="$(find ./ -type f ! -path '*/.git/*' | fzf)" + path="$(find . -type f ! -path '*/.git/*' | fzy)" + [ -z "$path" ] && exit 1 ;; + + # Multi-buffer editor vim ) - path="$(find ./ -type d ! -path '*/.git/*' ! -name .git | fzf)" - [ -z "$path" ] && exit 1 + path="$(find . -type d ! -path '*/.git/*' ! -name .git | fzy)" + cd "$path" + + [ -z "$path" ] && exit 0 ;; + + # Else, prompt for command * ) - read opt + read -p "$cmd > " opt + if [ -z "${opt##*\**}" -a "$opt" ] then - path="$(find -type f ./ | fzf)" + path="$(find . -type f | fzy)" opt="${opt##*\*} $path ${opt%%\**}" + [ -z "$path" ] && exit 1 fi ;; esac - # Set the name of the abduco session and create it - printf '\033]0;%s%s\007' "$name" "$path" - TERM=screen ABDUCO="$cmd" abduco -e '^z' \ - -A "$(printf '%s%s' "$cmd" "$path" | tr '/' '!')" $cmd $opt - ;; -a | attach ) - # If already on a session, print its name and exit + # Make the path name pretty + path="$(cd "$path"; pwd)" + [ -z "${path##$HOME*}" ] && path="~${path#$HOME}" + + # Set the name of the abduco session + printf '\033]0;%s %s\007' "$cmd" "$path" + + # Remove nasty chars from abduco session name + path="$(printf '%s' "$path" | tr '/' '!')" + + # Run new or existing abduco session with this name + TERM=screen ABDUCO="$cmd" abduco -e '^z' -A "$cmd $path" $cmd $opt +} + +# +# Attach to an existing abduco session. +# +attach() +{ + # If already on a session, print its name and exit. [ "$ABDUCO" ] && printf '[ %s ]\n' "$ABDUCO" | tr '!' '/' && exit 1 + # Overwrite the prompt. printf '\033[1A' - # get the session name by prompting the user - name="$(abduco | sed 1d | sort -k 4 | tr ! / | fzf | tr / !)" + # Get the session name by prompting the user. + name="$(abduco | sed 1d | sort -k 4 | tr ! / | fzy | tr / !)" name="${name##*$TAB}" - printf '%s\n' "$name" - # Set the name of the session and attath to it + # Set the name of the terminal. printf '\033]0;%s\007' "$name" | tr '!' '/' + + # Attach to the session. [ "$name" ] && TERM=screen ABDUCO="$name" abduco -e '^z' -a "$name" +} + +# ALGORITHM +#------------------------------------------------------------------------------- + +case "$1" in +r | run ) + shift + run "$1" + ;; +a | attach ) + attach ;; * ) printf '%s\n' "$help" exit 0 + ;; esac - +# # Reset the screen, print reminder of current sessions printf '\033[2J\033[0;0f\033[0m\n' abduco | tr '!' '/' | sort -t "$TAB" -k 3 | sed '1d; s/^/ /' diff --git a/dvtm/config.h b/dvtm/config.h @@ -232,7 +232,6 @@ static char const * const keytable[] = { * are generated in the output. */ static Editor editors[] = { - { .name = "piped", .argv = { "vis", "+%d", "-", NULL }, .filter = true, .color = false }, { .name = "vis", .argv = { "vis", "+%d", "-", NULL }, .filter = true, .color = false }, { .name = "sandy", .argv = { "sandy", "-d", "-", NULL }, .filter = true, .color = false }, { .name = "dvtm-editor", .argv = { "dvtm-editor", "-", NULL }, .filter = true, .color = false }, diff --git a/shell/.config/shell/environment b/shell/.config/shell/environment @@ -20,6 +20,7 @@ export VISUAL="$EDITOR" export FCEDIT="$EDITOR" export PAGER="less" export MANPAGER="$PAGER" +export DVTM_EDITOR="$PAGER" # DIRECTORIES diff --git a/shell/.profile b/shell/.profile @@ -19,7 +19,7 @@ # Black Red Green Yellow Blue Purple Cyan White THEMES="\ pink \ -P0090a0f P1f44444 P228684f P3c8907e P4422d52 P5710130 P62a7e86 P7777777 \ +P0090a0f P1f44444 P228684f P3c8907e P4422d52 P5710130 P62a7e86 P7999999 \ P83e4053 P9f44444 Pa43c291 Pbf49a7e Pc542a52 Pd9e0f37 Pe688e95 Pfffffff \ solarized_light \ @@ -72,12 +72,16 @@ P8709080 P9dca3a3 PAbfebbf PBf0dfaf PC94bff3 PDec93d3 PE93e0e3 PFffffff \ #------------------------------------------------------------------------------- export PS1='$( - local code="$?" + code="$?" # Error code [ "$code" -eq 0 ] && color=32 || color=31 printf "\n \033[1;30m>\033[0;%sm>\033[1m>\033[0m " "$color" + # Print path + [ -z "${PWD##$HOME*}" ] && pwd="~${PWD#$HOME}" || pwd="$PWD" + printf "\033]0;%s\007" "$pwd" + # Update tmux status line at each new prompt [ "$TMUX" ] && tmux refresh-client -S )' @@ -92,12 +96,14 @@ alias l='ls -F --color' alias ll='l -lh' alias la='l -A' alias lla='l -Alh' -alias v='$VISUAL' alias m='$PAGER' +alias a='buffers attach' +alias r='buffers run' +alias v='buffers run $VISUAL' alias t='tmux attach &>/dev/null || tmux new' -alias f='find . -type f ! -path "*/.git/*" | fzf --margin=3,6' -alias d='find . -type d ! -path "*/.git/*" | fzf --margin=3,6' -alias c='cd "$(find . -maxdepth 4 -mindepth 1 -type d | fzf --margin=3,6)"' +alias f='find . -type f ! -path "*/.git/*" | fzy' +alias d='find . -type d ! -path "*/.git/*" | fzy' +alias c='cd "$(find . -maxdepth 4 -mindepth 1 -type d | fzy)"' alias g='grep --color=always' alias myip='curl icanhazip.com' alias lines='find . -name "*.[ch]" | xargs wc -l' @@ -111,9 +117,3 @@ then theme pink setfont "$CONFIG/fonts/terminus/ter-v16b.psf.gz" fi - -# Attach to tmux right away -if [ -z "$TMUX" ] && command -v tmux &> /dev/null -then - tmux attach &> /dev/null || tmux new -fi diff --git a/vim/.vim/vimrc b/vim/.vim/vimrc @@ -53,10 +53,8 @@ nmap <Leader>t :pwd \| echo '' \| tags \| echo ''<CR>:tag nmap <Leader>" : echo '' \| registers <CR> nmap <Leader>' : echo '' \| marks <CR>:' nmap <Leader>m :silent !make clean<CR>:silent make \| redraw! \| clist<CR> -nmap <Leader>e :pwd \| exe 'e' system( - \ "find -type f ! -path '*/.svn/*' ! -path '*/.git/*' \| \ - \ fzf-tmux --margin=1,6" - \ )<CR> +let find_command = "find -type f ! -path '*/.svn/*' ! -path '*/.git/*' \| fzy" +nmap <Leader>e :e <C-r>=system(find_command)<CR> \| redraw!<CR> " <c>hange <o>ption <...> nmap col :set list ! \| set list ?<CR>