dot

packages and services management
Log | Files | Refs | README

commit a219f2ea878f0218658b2984de6999df2e811a2e
parent e27337d835be6b4aa6c409d31ef9cc26cb9517d8
Author: Josuah Demangeon⠠⠵ <mail@josuah.net>
Date:   Sat, 11 Mar 2017 23:59:12 +0100

Great cleanup

Diffstat:
M.config/dwm/config.h | 1+
D.exrc | 3---
M.profile | 127++++++++++++++++++-------------------------------------------------------------
Mbin/build | 20+++++++++-----------
Rbin/icaldir -> bin/cal-dir | 0
Abin/cal-show | 31+++++++++++++++++++++++++++++++
Dbin/calendar | 30------------------------------
Abin/extract | 16++++++++++++++++
Rbin/fig1 -> bin/fig-1 | 0
Rbin/fig2 -> bin/fig-2 | 0
Rbin/blawk -> bin/fig-blawk | 0
Rbin/drawk -> bin/fig-drawk | 0
Rbin/dna -> bin/fun-dna | 0
Rbin/lightsaber -> bin/fun-saber | 0
Rbin/gix -> bin/git-index | 0
Abin/io-abduco | 13+++++++++++++
Abin/io-edit | 46++++++++++++++++++++++++++++++++++++++++++++++
Abin/io-man | 6++++++
Abin/io-mblaze | 14++++++++++++++
Abin/io-run | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/io-setfont | 15+++++++++++++++
Rbin/mfilter -> bin/mail-filter | 0
Abin/mb-all | 1+
Abin/rfc | 5+++++
Abin/sam-man | 7+++++++
Abin/scr-brightness | 3+++
Abin/scr-cast | 7+++++++
Dbin/srv | 11-----------
Abin/srv-http | 3+++
Rbin/ii-server -> bin/srv-ii | 0
Abin/srv-irc | 5+++++
Abin/tty-rotate | 8++++++++
Abin/tty-video | 7+++++++
Rbin/index -> bin/www-index | 0
Rbin/www -> bin/www-tree | 0
Mbuild/iomenu | 2+-
36 files changed, 327 insertions(+), 154 deletions(-)

diff --git a/.config/dwm/config.h b/.config/dwm/config.h @@ -36,6 +36,7 @@ static const Rule rules[] = { { "Blender", NULL, NULL, 1 << 3, 0, -1 }, { "ffplay", NULL, NULL, 1 << 4, 0, -1 }, { "Pavucontrol", NULL, NULL, 1 << 4, 0, -1 }, + { "Sam", NULL, NULL, 1 << 1, 0, -1 }, }; /* layout(s) */ diff --git a/.exrc b/.exrc @@ -1,3 +0,0 @@ -" ex/vi editor configuration file -set number -set directory=/tmp diff --git a/.profile b/.profile @@ -1,26 +1,35 @@ # Shell configuration for any POSIX shell -# build(1) package manager runtime variables -[ "$(dirname "$(readlink ~/.profile)")/bin/build" ] && -. "$(dirname "$(readlink ~/.profile)")/bin/build" +[ "$CONFIG" ] || { +# paths +export CONFIG="$(dirname "$(readlink ~/.profile)")" +export PATH="$CONFIG/bin:$PATH" +export ENV="$HOME/.profile" +export MAIL="$HOME/mail/INBOX" -export PATH="$(dirname "$(readlink ~/.profile)")/bin:$PATH" -export ENV="$HOME/.profile" -export TZ='Europe/Paris' +# build(1) package manager runtime variables +[ "$CONFIG" ] && . "$CONFIG/bin/build" -# mail +# info export NAME='Josuah Demangeon' export EMAIL='mail@josuah.net' -export MAIL="$HOME/mail/INBOX" +export TZ='Europe/Paris' # default commands -export EDITOR='ex' VISUAL='ex' EXRC="$HOME/.exrc" -export PAGER='less' MANPAGER='less -R' DVTM_PAGER='less -R' +export EDITOR='ex' +export VISUAL='ex' EXRC="$HOME/.exrc" +export PAGER='less' +export MANPAGER='less -R' +export DVTM_PAGER='less -R' +export BROWSER='firefox' +export FILTER='iomenu' + +} -# prompt -export PS1='$( + +PS1='$( [ "$?" -gt 0 ] && color="1" || if git rev-parse 2>/dev/null then [ "$(git status -s)" ] && color="3" || color="2" fi @@ -31,8 +40,8 @@ export PS1='$( printf "\033]0;%s\007" "$(git-pwd)" # terminal name printf "\n%s \033[1;3%dm•\033[m%s " "$host" "${color:-7}" )' -export PS2=': ' -export PS3=': ' +PS2=': ' +PS3=': ' # core @@ -46,96 +55,18 @@ alias j='jobs' # iomenu alias a='io-abduco' alias r='io-run' -alias v='io-files' -alias m='io-man' -alias mb='io-mblaze' +alias e='io-edit' alias f='find ! -path "*/.git/*" -type f | iomenu' alias d='find ! -path "*/.git/*" -type d | iomenu' alias c='cd "$(find ! -path "*/.git/*" -type d | iomenu)"' -# scripts -alias i='ii-client' - -# tmux -alias t='tmux attach &>/dev/null || tmux new' - # utilities alias myip='curl icanhazip.com' -alias lines='find . -name "*.[ch]" | sort -g | xargs wc -l' +alias lines='find . -name "*.[ch]" | xargs wc -l | sort -g' alias ix='curl -F "f:1=<-" ix.io' -alias mnt='sudo mount -o uid="$USER" -o rw' - - -extract() -{ - case "$1" in - ( *.tar.gz | *.tgz ) tar -xzf "$1" ;; - ( *.tar.bz2 | *.tbz2 ) tar -xjf "$1" ;; - ( *.tar ) tar -xf "$1" ;; - ( *.bz2 ) bunzip2 "$1" ;; - ( *.gz ) gunzip "$1" ;; - ( *.rar ) unrar x "$1" ;; - ( *.zip ) unzip "$1" ;; - ( *.Z ) uncompress "$1" ;; - ( *.7z ) 7z x "$1" ;; - ( *.xz ) xz -d "$1" ;; - ( *.deb ) ar vx "$1" ;; - ( * ) exit 1 ;; - esac -} - - -brightness() -{ - printf %s "$1" | sudo tee -a "$( - find -L /sys/class/backlight -maxdepth 2 -name brightness - )" -} - - -rotate() -{ - case "$1" in - ( u ) printf 0 ;; ( r ) printf 1 ;; ( d ) printf 2 ;; ( l ) printf 3 ;; - esac | sudo tee /sys/class/graphics/fbcon/rotate_all > /dev/null -} - - -fbvideo() -{ - mplayer -vm -vo fbdev2 "$1" -vf scale -zoom -x "$( - sed 's/,.*//' /sys/class/graphics/fb0/virtual_size - )" -y "$( - sed 's/.*,//' /sys/class/graphics/fb0/virtual_size - )" -} - - -screencast() -{ - ffmpeg -framerate 25 -f x11grab -i :0.0 -video_size "$( - sed 's/,.*//' /sys/class/graphics/fb0/virtual_size - )x$( - sed 's/.*,//' /sys/class/graphics/fb0/virtual_size - )" ~"/${1:-screencast}.mp4" -} - - -rfc() -{ - wget -q -O- http://www.ietf.org/rfc/rfc"$1".txt | - awk -v RS='\n\n[^\n]*\n\f\n[^\n]*\n\n\n' '{ print; }' | - less -} - - -main() -{ - if [ "$TERM" = 'linux' ] - then - setfont ~/.local/share/consolefonts/terminus-16n.psf - fi -} -main "$@" +if [ "$TERM" = 'linux' ] +then + setfont "$CONFIG/consolefonts/terminus-16n.psf" +fi diff --git a/bin/build b/bin/build @@ -1,8 +1,9 @@ # Install sources from build receipes +export BUILD="${0%/*}/../build" export LOCAL="$HOME/.local" -export CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}" +export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" export PROGRAMS="$HOME/programs" export PATH="$LOCAL/sbin:$LOCAL/bin:$PATH" export CPATH="$LOCAL/include:$CPATH" @@ -15,9 +16,6 @@ export LD_LIBRARY_PATH="$LOCAL/lib:$LD_LIBRARY_PATH" [ "${0##*/}" = build ] && { -BUILD="${0%/*}/../build" - - usage() { printf %s "\ @@ -43,7 +41,7 @@ view() } -error() +die() { printf '\033[31m%-12s \033[1m%s\033[m\n' "$1" "$2" 1>&2; exit 1 } @@ -60,9 +58,9 @@ info() # build() { - find "$CONFIG/$1" -name '*.diff' -exec patch -N -p 1 -i {} \; + find "$XDG_CONFIG_HOME/$1" -name '*.diff' -exec patch -N -p 1 -i {} \; - for file in "$CONFIG/$1/config.mk" "$CONFIG/$1/config.h" + for file in "$XDG_CONFIG_HOME/$1/config.mk" "$XDG_CONFIG_HOME/$1/config.h" do [ -h "$file" ] || [ -f "$file" ] && cp -f "$file" . done @@ -83,7 +81,7 @@ compile() export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 export CFLAGS="-I $LOCAL/include -L$LOCAL/lib -static" - [ -f "$script" ] || [ -h "$script" ] || error "$name" "no build script" + [ -f "$script" ] || [ -h "$script" ] || die "$name" "no build script" . "$script" info "$name" "installing" @@ -98,8 +96,8 @@ download() { name="$1" tar="$2" script="$BUILD/$name" - [ -d "$PROGRAMS/$name/src" ] && error "$name" "already in $PROGRAMS" - [ -f "$script" ] || [ -h "$script" ] || error "$name" "no build script" + [ -d "$PROGRAMS/$name/src" ] && die "$name" "already in $PROGRAMS" + [ -f "$script" ] || [ -h "$script" ] || die "$name" "no build script" . "$script" info "$name" "downloading" @@ -109,7 +107,7 @@ download() *.tbz2 | *.tar.bz2 ) opt='j' ;; *.tgz | *.tar.gz ) opt='z' ;; *.txz | *.tar.xz ) opt='J' ;; - * ) error "$name" 'not a known tar extension' ;; + * ) die "$name" 'not a known tar extension' ;; esac mkdir -p "$PROGRAMS/$name" diff --git a/bin/icaldir b/bin/cal-dir diff --git a/bin/cal-show b/bin/cal-show @@ -0,0 +1,31 @@ +# command line calendar (WIP) + +awk ' +function is_bissextile(year) +{ + return (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0); +} + + +function days_in_month(month, year) +{ + if (month == 2) { + return 28 + is_bissextile(year); + } else if (month < 8) { + return 30 + (month % 2 == 1); + } else { + return 30 + (month % 2 == 0); + } +} + + +function to_seconds(year, month, day, hour, minute, second) +{ + for (month--; month > 0; month--) + day += days_in_month(month, year); + + for (year--; year >= 1970; year--) + day += 365 + is_bissextile(year); + + return (second + 60 * (minute + 60 * (hour + (24 * (day - 1))))); +}' diff --git a/bin/calendar b/bin/calendar @@ -1,30 +0,0 @@ -awk ' -# command line calendar (WIP) -function is_bissextile(year) -{ - return (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0); -} - - -function days_in_month(month, year) -{ - if (month == 2) { - return 28 + is_bissextile(year); - } else if (month < 8) { - return 30 + (month % 2 == 1); - } else { - return 30 + (month % 2 == 0); - } -} - - -function to_seconds(year, month, day, hour, minute, second) -{ - for (month--; month > 0; month--) - day += days_in_month(month, year); - - for (year--; year >= 1970; year--) - day += 365 + is_bissextile(year); - - return (second + 60 * (minute + 60 * (hour + (24 * (day - 1))))); -}' diff --git a/bin/extract b/bin/extract @@ -0,0 +1,16 @@ +# extract an archive file given its extension + +case "$1" in +( *.tar.gz | *.tgz ) tar -xzf "$1" ;; +( *.tar.bz2 | *.tbz2 ) tar -xjf "$1" ;; +( *.tar ) tar -xf "$1" ;; +( *.bz2 ) bunzip2 "$1" ;; +( *.gz ) gunzip "$1" ;; +( *.rar ) unrar x "$1" ;; +( *.zip ) unzip "$1" ;; +( *.Z ) uncompress "$1" ;; +( *.7z ) 7z x "$1" ;; +( *.xz ) xz -d "$1" ;; +( *.deb ) ar vx "$1" ;; +( * ) exit 1 ;; +esac diff --git a/bin/fig1 b/bin/fig-1 diff --git a/bin/fig2 b/bin/fig-2 diff --git a/bin/blawk b/bin/fig-blawk diff --git a/bin/drawk b/bin/fig-drawk diff --git a/bin/dna b/bin/fun-dna diff --git a/bin/lightsaber b/bin/fun-saber diff --git a/bin/gix b/bin/git-index diff --git a/bin/io-abduco b/bin/io-abduco @@ -0,0 +1,13 @@ +# Prompt for an abduco session to attach to with $FILTER + +if [ "$ABDUCO" ] +then + printf 'session already active: %s\n' "$ABDUCO" + exit 1 +fi + +name="$(abduco | tail -n +2 | $FILTER | sed -r 's/[^\t]*\t[^\t]*\t//')" + +[ "$SSH_CLIENT$SSH_TTY$SSH_CONNECTION" ] && e='^\' || e='^Z' + +[ "$name" ] && ABDUCO="$name" exec abduco -e "$e" -A "$name" "$SHELL" diff --git a/bin/io-edit b/bin/io-edit @@ -0,0 +1,46 @@ +# Prompt a file to open in PAGER, with an history. In less(1), 'v' to edit. + + +CACHE="${XDG_CACHE_HOME:-$HOME/.cache}" + + +path() +{ + if [ -f "$1" ] + then + printf '%s\n' "$([ -d "${1%/*}" ] && cd "${1%/*}"; pwd)/${1##*/}" + else + [ -f "$CACHE/files" ] && tac "$CACHE/files" | $FILTER + fi | tee -a "$CACHE/files" +} + + +history() +{ + sort "$CACHE/files" | uniq -d | while IFS='' read -r path + do + printf '%s\n' "$( + grep -Fxv "$path" "$CACHE/files" + )" "$path" > "$CACHE/files" + done + + printf '%s\n' "$(tail "$CACHE/files")" > "$CACHE/files" +} + + +main() +{ + mkdir -p "$CACHE" + touch "$CACHE/files" + + file="$(path "$1")" + + # terminal name + printf '\033]0;%s\007' "$file" + history + + [ "$file" ] && [ -d "${file%/*}" ] && exec $EDITOR "$file" +} + + +main "$@" diff --git a/bin/io-man b/bin/io-man @@ -0,0 +1,6 @@ +# prompt a man page to open + +mandoc -a "$( + IFS=':' + find $MANPATH ! -type d -name '*.[0-9]' | sort -u | $FILTER +)" diff --git a/bin/io-mblaze b/bin/io-mblaze @@ -0,0 +1,14 @@ +T=' ' +choice="$( + mdirs "${MAIL%/*}" | while IFS='' read -r dir + do + mlist "$dir" | mpick :u | msort -d | mthread | + mscan -f '%D %24f %u%t%2i%120S' + + done | $FILTER +)" + +[ "$choice" ] || exit 0 + +mlist "${MAIL%/*}/${choice%%$T*}" | mpick :u | msort -d | mthread | +sed -n "${choice#*$T}p" | mshow | $PAGER diff --git a/bin/io-run b/bin/io-run @@ -0,0 +1,100 @@ +# Prompt for a programs to run + + +CACHE="${XDG_CACHE_HOME:-$HOME/.cache}" + + +usage() +{ + printf 'Usage: %s [cmd [args...] [+]] + +cmd do not prompt for a command and run cmd right away +args do not prompt for arguments neither and use arg ++ if present after the arguments, prompt for a path\n' "${0##*/}" +} + + +# +# Update the cache and get the command to run. +# +update_cache() +( + IFS=':' u=0 + + for dir in $PATH + do + [ "$CACHE/dmenu_run" -ot "$dir" ] && u=1 + done + + [ "$u" -eq 1 ] && find -L $PATH -type f -exec test -x {} \; -print | + sed 's|.*/||' | sort -u > "$CACHE/dmenu_run" +) + + +# +# Prompt for options for a given command and log it to an history file +# +get_options() +( + local command="$1" + + printf '%s ' "$command" >> "$CACHE/iomenu/run" + + while read -r cmd opt + do + [ "$command" = "$cmd" ] && printf '%s\n' "$opt" + done < "$CACHE/iomenu/run" | + iomenu -p "$command" | tee -a "$CACHE/iomenu/run" + + sort -u "$CACHE/iomenu/run" -o "$CACHE/iomenu/run" +) + + +# +# Prompt for a file path in $HOME and print it. +# +get_path() +( + find "$HOME" ! -path "$CACHE" ! -path '*/.git/*' | + sed -r "s/.{${#HOME}}/~/" | iomenu -l 256 | sed 's/^~//' +) + + +# +# Get the options according to the command and run it +# +run() +( + command="${1:-$(iomenu -l 256 -s '#' < "$CACHE/dmenu_run")}" + + [ -z "$command" ] && exit 1 + + options="$(get_options "$command")" + + if [ "$options" ] && [ -z "${options%%*+}" ] + then + path="$(get_path)" options="${options%+}" + fi + + if [ "$path" ] + then exec $command $options "$path" + else exec $command $options + fi +) + + +main() +( + mkdir -p "$CACHE/iomenu" + + if [ $# -gt 0 ] && [ -z "${1##-*}" ] + then + usage + else + update_cache + run "$@" + fi +) + + +main "$@" diff --git a/bin/io-setfont b/bin/io-setfont @@ -0,0 +1,15 @@ +# set tty font using "$FILTER" + +setfont "$( + while IFS='' read dir + do + [ -d "$dir" ] && find "$dir" -type f | sort + + done <<EOF | $FILTER +/usr/share/kbd/consolefonts +/usr/share/consolefonts +/share/kbd/consolefonts +/share/consolefonts +$CONFIG/consolefonts +EOF +)" diff --git a/bin/mfilter b/bin/mail-filter diff --git a/bin/mb-all b/bin/mb-all @@ -0,0 +1 @@ +mdirs "${MAIL%/*}" | xargs mlist | msort -r -d | mseq -S | mscan | $FILTER diff --git a/bin/rfc b/bin/rfc @@ -0,0 +1,5 @@ +# download and print an RFC from ietf.org + +wget -q -O- http://www.ietf.org/rfc/rfc"$1".txt | +awk -v RS='\n\n[^\n]*\n\f\n[^\n]*\n\n\n' '{ print; }' | +less diff --git a/bin/sam-man b/bin/sam-man @@ -0,0 +1,7 @@ +# open a man page in sam(1) + +tmp="$(mktemp)" + +man "$@" | sed 's/.//g' > "$tmp" + +B "$tmp" diff --git a/bin/scr-brightness b/bin/scr-brightness @@ -0,0 +1,3 @@ +printf %s "$1" | sudo tee -a "$( + find -L /sys/class/backlight -maxdepth 2 -name brightness +)" diff --git a/bin/scr-cast b/bin/scr-cast @@ -0,0 +1,7 @@ +# record screen content to a video using ffmpeg + +ffmpeg -framerate 25 -f x11grab -i :0.0 -video_size "$( + sed 's/,.*//' /sys/class/graphics/fb0/virtual_size +)x$( + sed 's/.*,//' /sys/class/graphics/fb0/virtual_size +)" ~"/${1:-screencast}.mp4" diff --git a/bin/srv b/bin/srv @@ -1,11 +0,0 @@ -case "$1" in - -( irc ) - ngircd -f ~/.config/ngircd/ngircd.conf - ii -s 0.0.0.0 -n daemon & - node ~/node_modules/thelounge/index.js - ;; - -( http ) - sudo $(which darkhttpd) ~/www --daemon -esac diff --git a/bin/srv-http b/bin/srv-http @@ -0,0 +1,3 @@ +# start http server as root on port :80 + +sudo $(which darkhttpd) ~/www --daemon diff --git a/bin/ii-server b/bin/srv-ii diff --git a/bin/srv-irc b/bin/srv-irc @@ -0,0 +1,5 @@ +# start the irc stakc: server, logs, web interface + +ngircd -f ~/.config/ngircd/ngircd.conf +ii -s 0.0.0.0 -n daemon & +node ~/node_modules/thelounge/index.js diff --git a/bin/tty-rotate b/bin/tty-rotate @@ -0,0 +1,8 @@ +# rotate the screen while in TTY + +case "$1" in +( u | up ) printf 0 ;; +( r | right ) printf 1 ;; +( d | down ) printf 2 ;; +( l | left ) printf 3 ;; +esac | sudo tee /sys/class/graphics/fbcon/rotate_all > /dev/null diff --git a/bin/tty-video b/bin/tty-video @@ -0,0 +1,7 @@ +# play a video in current TTY using mplayer + +mplayer -vm -vo fbdev2 "$1" -vf scale -zoom -x "$( + sed 's/,.*//' /sys/class/graphics/fb0/virtual_size +)" -y "$( + sed 's/.*,//' /sys/class/graphics/fb0/virtual_size +)" diff --git a/bin/index b/bin/www-index diff --git a/bin/www b/bin/www-tree diff --git a/build/iomenu b/build/iomenu @@ -1,3 +1,3 @@ # Input/Output interactive menu and completion engine. -tar=http://repo.or.cz/iomenu.git/snapshot/HEAD.tar.gz +tar=http://github.com/josuah/iomenu/archive/master.tar.gz