dot

packages and services management
Log | Files | Refs | README

commit 8648e741022f6fd821d047fc388365a3c55fb301
parent 828af4b95a42794838ca13876bb30599cd80bee7
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun, 30 Apr 2017 17:48:43 +0200

Union.  Layer 09

Diffstat:
M.profile | 46++++++++++++++++++++++++++++++++++++++++------
Mbin/io | 86++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Abin/io-abduco | 5+++++
Abin/io-files | 3+++
Dbin/io-ii | 30------------------------------
Dbin/io-ii-talk | 9---------
Abin/io-irc | 3+++
Abin/io-mail | 10++++++++++
Abin/io-man | 3+++
Dbin/io-mandoc | 9---------
Dbin/io-mblaze | 16----------------
Mbin/io-music | 17+----------------
Dbin/io-path | 18------------------
Mbin/io-run | 15++++-----------
Mbin/io-search | 30+++++++++++++++++++-----------
Mbin/io-url | 19++++++++++++-------
16 files changed, 152 insertions(+), 167 deletions(-)

diff --git a/.profile b/.profile @@ -10,16 +10,28 @@ OPT="$HOME/opt" SRC="$HOME/src" ETC="$HOME/etc" ROOT="$HOME/.local" -export OPT SRC ETC ROOT +export OPT SRC ETC VAR BIN ROOT -# paths +# data paths + +GIT="$HOME/git" +IRC="$HOME/var/irc" +MAIL="$HOME/var/mail/INBOX" +MUSIC="$HOME/music" +export GIT IRC MAIL MUSIC + + +# system paths ENV="$HOME/.profile" -PATH="$ETC/bin:$ROOT/bin:$PATH:$PLAN9/bin" +PATH="$( + printf %s "$ETC/bin:$ROOT/bin:$PATH:$PLAN9/bin" | + awk -v RS=':' -v ORS=':' '!path[$0] { path[$0] = 1; print; }' | + sed 's/:$//' +)" MANPATH="$ETC/man:$ROOT/share/man:$ROOT/man:$MANPATH" -MAIL="$HOME/var/mail/INBOX" -export ENV PATH MANPATH MAIL +export ENV MANPATH # libraries @@ -72,4 +84,26 @@ esac # aliases -. "$ETC/alias" +# core +alias l='ls -lp' +alias la='ls -lpA' +alias cl='printf "\033[H\033[2J"' +alias ..='cd ..' + +# iomenu +alias r='io-run' +alias j='fg "%$(jobs | iomenu | sed -r "s/.([0-9]*).*/\1/")"' +alias f='find . ! -path "*/.git/*" -type f | iomenu -p file' +alias d='find . ! -path "*/.git/*" -type d | iomenu -p directory' +alias c='cd "$(find "$HOME" -type d | iomenu -p cd)"' + +# utilities +alias inv='printf "\033[?5%s" h' +alias myip='curl icanhazip.com' +alias ix='curl -F "f:1=<-" ix.io' +alias wttr='wget -qO- wttr.in' +alias lines='find . -name "*.[ch]" | xargs wc -l | sort -g' +alias count='echo "$(( + $(git diff | grep "^+" | wc -l) - + $(git diff | grep "^-" | wc -l) +))"' diff --git a/bin/io b/bin/io @@ -1,55 +1,71 @@ -# Attach to an abduco session +# filter lines and sort them into categories to be open with different tools -CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/io" - [ "$ABDUCO" ] && exit 1 -mkdir -p "$CACHE/find" -touch "$CACHE/files" +CACHE="${XDG_CACHE_DIR:-$HOME/.cache}" +mkdir -p "$CACHE/io" +touch "$CACHE/io/io" -# --- caching find ------------------------------------------------------------- +# --- prompt ------------------------------------------------------------------- -find "$HOME" -maxdepth 1 -mindepth 1 -type d | sort | sed 's|.*/||' | -while IFS='' read -r dir -do - [ "$CACHE/find/$dir" -ot "$HOME/$dir" ] && - find "$HOME/$dir" -type f ! -path '*/.git/*' | sort > "$CACHE/find/$dir" -done +selection="$({ + printf '# abduco\n' + abduco | sed '1d; s/.*\t//; y|!|/|' -# --- prompt ------------------------------------------------------------------- +} | cat - "$CACHE/io/io" | iomenu -p io -s -h)" -file="$({ - printf '# ' - abduco | sed 's/.*\t//; s|!|/|g' - printf '# Recent files\n' - tac "$CACHE/files" +# --- history ------------------------------------------------------------------ - printf '# All files\n' - find "$HOME" -maxdepth 1 -type f | sort - find "$HOME" -maxdepth 1 -mindepth 1 -type d | sed 's|.*/||' | - xargs -I % cat "$CACHE/find/%" +printf '%s\n' "$selection" >> "$CACHE/io/files" -} | iomenu -s -p io)" +printf '%s\n' "$( + awk '!line[$0] { line[$0] = 1; print }' "$CACHE/io/files" | tail +)" > "$CACHE/io/files" -name="$(printf %s "$file" | sed 's|/|!|g')" +# --- cache -------------------------------------------------------------------- -# --- history ------------------------------------------------------------------ +list="$( + find "$HOME" \ + -path "$HOME/.*" -prune -o \ + -path "*/.git/*" -prune -o \ + -path "*/v" -prune -o \ + -path "${MAIL%/*}/*/*" -prune -o \ + -type d -exec printf '%s/\n' {} + -o \ + -print | sort +)" && { + + printf '# irc\n' + printf '%s\n' "$list" | grep "$IRC/.*/$" -[ -f "$file" ] && printf '%s\n' "$file" >> "$CACHE/files" + printf '# mail\n' + printf '%s\n' "$list" | grep "${MAIL%/*}" -sort "$CACHE/files" | uniq -d | while IFS='' read -r path -do - printf '%s\n' "$( - grep -Fxv "$path" "$CACHE/files" - )" "$path" > "$CACHE/files" -done + printf '# git\n' + printf '%s\n' "$list" | grep '\.git/' -printf '%s\n' "$(sed '/^$/d' "$CACHE/files" | tail)" > "$CACHE/files" + printf '# search\n' + printf '%s\n' "$list" | grep '/src/[^/]*/$' + + printf '# music\n' + printf '%s\n' "$list" | grep "$MUSIC" + + printf '# man\n' + printf '%s\n' "$list" | grep '\.[1-9]\(.gz\)\?$' + + printf '# files\n' + printf '%s\n' "$list" | grep '[^/]$' + +} > "$CACHE/io/io" & + +selection="${selection#\# }" +command="io-${selection%% *}" +path="${selection#* }" +name="$(printf %s "$path" | tr '/' '!')" # --- attach ------------------------------------------------------------------- @@ -57,4 +73,6 @@ printf '%s\n' "$(sed '/^$/d' "$CACHE/files" | tail)" > "$CACHE/files" printf '\033[H\033[2J' [ "$SSH_TTY" ] && e='^\' || e='^Z' -[ "$name" ] && ABDUCO="$name" exec abduco -e "$e" -A "$name" $EDITOR "$file" + +command -v "$command" && [ "$name" ] && +ABDUCO="$name" exec abduco -e "$e" -A "$name" $command "$path" diff --git a/bin/io-abduco b/bin/io-abduco @@ -0,0 +1,5 @@ +# just attach to an abduco session + +set -- "$(printf %s "$1" | tr '/' '!')" + +ABDUCO="$1" exec abduco -a "$1" diff --git a/bin/io-files b/bin/io-files @@ -0,0 +1,3 @@ +# Attach to an abduco session + +[ -f "$1" ] && $EDITOR "$1" diff --git a/bin/io-ii b/bin/io-ii @@ -1,30 +0,0 @@ -# a pager to browse ii channels - -T=' ' -name='.' - -while [ "$name" ] -do - name="$( - { - printf '# Read\n' - find "${IRC:-$HOME/var/irc}" -mindepth 1 -type d - - printf '# Talk\n' - find "${IRC:-$HOME/var/irc}" -mindepth 1 -type d - } | iomenu -p ii -s -h - )" - mode="${name%%$T*}" - name="${name#*$T}" - - if [ -z "${mode### Read}" ] && [ -f "$name/out" ] - then - less "$name/out" - - elif [ -z "${mode### Talk}" ] && [ -p "$name/in" ] - then - printf '\033[7m message \033[m '; read message - [ "$message" ] && printf '%s\n' "$message" >> "$dir/in" - fi -done - diff --git a/bin/io-ii-talk b/bin/io-ii-talk @@ -1,9 +0,0 @@ -# Send a message to a channel - -dir="$(find "${IRC:-$HOME/var/irc}" -type p | sed 's/in$//' | iomenu -p talk)" -[ -d "$dir" ] || exit 1 - -printf '\033[7m message \033[m ' -read message - -[ "$message" ] && printf '%s\n' "$message" >> "$dir/in" diff --git a/bin/io-irc b/bin/io-irc @@ -0,0 +1,3 @@ +# a pager to browse ii channels + +[ -d "$1" ] && cd "$1" && less out diff --git a/bin/io-mail b/bin/io-mail @@ -0,0 +1,10 @@ +# list mail from all inboxes using mblaze + +# sort messages +mdirs "$1" | mlist | msort -r -d | mthread | mseq -S | + +# prompt for a mail with iomenu +mscan -f '%6n %u %D %20f %t%2i%120S' | iomenu -p mail | + +# open it +sed -r 's/^ *([0-9]*) .*/\1/'| xargs mless diff --git a/bin/io-man b/bin/io-man @@ -0,0 +1,3 @@ +# just open a man page + +mandoc -a "$1" diff --git a/bin/io-mandoc b/bin/io-mandoc @@ -1,9 +0,0 @@ -# prompt a man page to open - -mandoc -a "$( - IFS=':' - find $MANPATH /usr/share/man ! -type d \ - -name '*.[0-9]' -o -name '*.[0-9].gz' | - sort -u | - iomenu -p mandoc -l 255 -)" diff --git a/bin/io-mblaze b/bin/io-mblaze @@ -1,16 +0,0 @@ -# list mail from all inboxes using mblaze - -# get the main mail directory with all mailing lists -dirname "$MAIL" | - -# find all mailboxes from it -xargs -I % find % -type d -mindepth 1 ! -name cur ! -name new ! -name tmp | - -# prompt for a mailbox and sort messages -iomenu -p mblaze | xargs mdirs | mlist | msort -r -d | mseq -S | - -# prompt for a mail with iomenu -mscan -f '%6n %u %D %20f %t%2i%120S' | iomenu -p mblaze | - -# open it -sed -r 's/^ *([0-9]*) .*/\1/'| xargs mless diff --git a/bin/io-music b/bin/io-music @@ -1,18 +1,3 @@ # play all music from directories and files passed as argument with mplayer -MUSIC="$HOME/music" - -path="$( - cd "$MUSIC" || exit 1 - find . | sort | iomenu -l 255 -p music -)" - -IFS=' -' - -mplayer $( - for path in $path - do - find "$MUSIC/$path" -type f -name '*.flac' | sort - done -) +mplayer $(find "$1" -type f -name '*.flac' | sort) diff --git a/bin/io-path b/bin/io-path @@ -1,18 +0,0 @@ -# prompt for a path recursively - -if [ "$1" = './' ] -then - printf '%s' "$PWD" - exit 0 - -elif [ -d "$1" ] -then - cd "$1" - -elif [ "$#" -gt 0 ] -then - printf '%s/%s\n' "$PWD" "$1" - exit 0 -fi - -$0 "$(ls -ap | iomenu -p "$PWD")" || exit 1 diff --git a/bin/io-run b/bin/io-run @@ -1,25 +1,18 @@ # prompt for a programs to run -CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/io" +CACHE="${XDG_CACHE_HOME:-$HOME/.cache}" # --- commands cache ----------------------------------------------------------- IFS=':' -[ ! -f "$CACHE/run" ] && UPDATE='1' || for path in $PATH -do - [ "$CACHE/run" -ot "$path" ] && UPDATE='1' && break -done - -[ "$UPDATE" ] && -find -L . $PATH -maxdepth 1 -type f -exec test -x {} \; -print | -sed 's/.*\///' | sort -u -o "$CACHE/run" +stest -dqr -n "$CACHE/io/run" $PATH && +stest -flx $PATH | sort -u > "$CACHE/io/run" unset IFS - # --- run ---------------------------------------------------------------------- command="$({ @@ -27,7 +20,7 @@ command="$({ abduco | sed 's/.*\t//' | sed 's|!|/|g' printf '# Commands\n' - cat "$CACHE/run" + cat "$CACHE/io/run" } | iomenu -s -p run )" name="$(printf %s "$command" | sed 's|/|!|g')" diff --git a/bin/io-search b/bin/io-search @@ -1,11 +1,19 @@ -# interactively search string in code - -find "$HOME" -type d ! -path '*/.git/*' | iomenu -p search | -xargs -I % find % -type f ! -path '*/.git/*' | -xargs -n 1 awk ' - FNR == 1 { printf("# %s\n", FILENAME); } - { printf("%7s\t%s\n", FNR, $0); } -' | iomenu -s -h | { - IFS=' ' read -r path number content - ${EDITOR:-vi} +"$number" "${path#\# }" -} +# interactively search a string in all code of a directory + +IFS=' ' read -r path number content << EOF +$( + find "$1" -type f ! -path '*/.git/*' | + xargs -n 1 awk ' + FNR == 1 { printf("# %s\n", FILENAME); } + { printf("%7s\t%s\n", FNR, $0); } + ' | iomenu -s -h +) +EOF + +[ "$path" ] || exit 1 + +[ "$SSH_TTY" ] && e='^\' || e='^Z' +path="${path#\# }" +name="$(printf %s "$path" | tr '/' '!')" + +ABDUCO="$name" exec abduco -e "$e" -A "$name" $EDITOR +"$number" "$path" diff --git a/bin/io-url b/bin/io-url @@ -1,6 +1,12 @@ # open a link from $CONFIG/url appropritately -url="$(iomenu -s -p 'url' < "$ETC/url")" +url="$( + { + printf '# ' + abduco | sed 's/.*\t//' + cat "$ETC/url" + } | iomenu -s -p 'url' +)" name="$(printf %s "$url" | sed 's|/|!|g')" [ "$SSH_TTY" ] && e='^\' || e='^Z' @@ -18,11 +24,10 @@ case "$url" in ;; ( irc://* ) ABDUCO="$name" exec abduco -e "$e" -A "$name" \ - ii \ - -i "${IRC:-$HOME/var/irc}" \ - -n "${NICK:-$USER}" \ - -f "$NAME" \ - -s "${url#irc://}" \ - -e 6697 + ii -i "${IRC:-$HOME/var/irc}" \ + -n "${NICK:-$USER}" \ + -f "$NAME" \ + -s "${url#irc://}" \ + -e 6697 ;; esac