dot

packages and services management
Log | Files | Refs | README

commit b08a22f75f64edcef7961333be34bdaa64843fbf
parent b603af2c83c2a69c55391e67ce242188f0167986
Author: josuah <mail@josuah.net>
Date:   Tue, 24 Jan 2017 15:59:30 +0100

Simplified io-ii into iirc.

Diffstat:
M.local/bin/ii-server | 63++++++++++++++++++---------------------------------------------
D.local/bin/iii | 133-------------------------------------------------------------------------------
A.local/bin/iirc | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.sh | 8++++----
4 files changed, 149 insertions(+), 182 deletions(-)

diff --git a/.local/bin/ii-server b/.local/bin/ii-server @@ -1,60 +1,33 @@ # connect to an irc server with ii and maintain connection active -DIR="$HOME/.cache/irc" -LOG="$DIR/errors" +DIR="$HOME/irc" -usage() -{ - printf '%s [-n NICK] [-f FULLNAME] SERVER...\n' "${0##*/}" -} - - -# 1: irc channel to connect to -# 2: nick name -# 3: full name - connect() { - if pgrep -f "^ii .*-s $1" > /dev/null - then - printf '\033[31m%s: \033[1malreadiy running\033[m\n' "$1" - else - (exit 2) - while [ "$?" -eq 2 ] - do nohup ii -i "$DIR" -n "$2" -f "$3" -p 6667 -s "$1" 2> "$LOG" - done & - fi + (exit 2) + while [ "$?" -eq 2 ] + do + nohup ii -i "$DIR" -p 6667 "$@" > "$DIR/errors" + done & } main() { - [ $# -eq 0 ] && usage - while [ $# -gt 0 ] - do - case "$1" in - ( -n ) - NICK="$2" - shift - ;; - ( -f ) - FULL="$2" - shift - ;; - ( -* ) - usage - ;; - ( * ) - connect "$1" "${NICK:-$USER}" "${FULL:-${NICK:-$USER}}" - ;; - esac - shift - done - - pgrep -fl '^ii ' - return 1 + mkdir -p "$DIR" + + pgrep -fla '^ii ' + printf '\nDo you want to start ii in the background ? [Y/n] ' + + read -r answer + + case "$answer" in + ( y | Y | '' ) + connect "$@" + ;; + esac } diff --git a/.local/bin/iii b/.local/bin/iii @@ -1,133 +0,0 @@ -# wrapper script for ii irc client http://tools.suckless.org/ii - - -II_DIR="$HOME/.cache/irc" - - -# -# Read one character from /dev/tty in raw mode. -# -get_char() -{ - stty -echo raw - dd count=1 2> /dev/null - stty sane -} - - -# -# Manage characters typed by user. -# -input() -{ - printf '' > input - - print_prompt - - while key="$(get_char)" - do - case "$key" in - ( [[:print:]] ) - printf %s "$key" >> input - ;; - - ( "$(printf '\020')" | "$(printf '\016')" ) # Ctrl-P Ctrl-N - ;; - - ( "$(printf '\033')" | "$(printf '\003')" ) # Escape Ctrl-C - exit 0 - ;; - - ( "$(printf '\015')" ) # Ctrl-M Enter - IFS='' read -r channel < channel - sed 's/$/\n/' input > "$channel/in" - printf '' > input - ;; - - ( "$(printf '\025')" ) # Ctrl-U - printf '' > input - ;; - - ( "$(printf '\027')" ) # Ctrl-W - sed -i 's/[^ \t]* *$//' input - ;; - - ( "$(printf '\010')" | "$(printf '\177')" ) # Ctrl-H Backspace - sed -i 's/.$//' input - ;; - - ( "$(printf '\014')" ) # Ctrl-L - IFS='' read -r channel < channel - less "$channel/out" - print_screen - ;; - esac - - print_prompt - done -} - - -# -# Print a prompt with the current input -# -print_prompt() -{ - size="$(stty -F /dev/tty size)" - - IFS='' read -r channel < channel - IFS='' read -r input < input - - width="$(((${#input} + ${#channel} + 4) - ${size#* }))" - - if [ "$width" -gt 0 ] - then - input="$(printf %s "$input" | cut -c "$width"- | tr -d '\n')" - fi - - printf '\r\033[K%s> %s' "$channel" "$input" -} - - -# -# Update the buffer lines and prompt -# -print_screen() -{ - size="$(stty -F /dev/tty size)" - - stty sane - - printf '\033[H\033[J' - [ -f out ] && tail -n "${size#* }" out - print_prompt - - stty raw -} - - -# -# Print lines after formatting them and update the prompt. -# -print_lines() -{ - while IFS='' read -r line - do - printf '\a\r\033[K%s\n' "$line" - print_prompt - done -} - - -main() -{ - touch channel in - - trap 'print_screen' SIGWINCH - trap 'stty sane; stop' EXIT - - input -} - - -main "$@" diff --git a/.local/bin/iirc b/.local/bin/iirc @@ -0,0 +1,127 @@ +# wrapper script for ii irc client http://tools.suckless.org/ii + + +II_DIR="$HOME/.cache/irc" + + +# +# Read one character from /dev/tty in raw mode. +# +get_char() +{ + stty -echo raw + dd count=1 2> /dev/null + stty sane +} + + +# +# Manage characters typed by user. +# +input() +{ + printf '' > input + + print_prompt + + while key="$(get_char)" + do + case "$key" in + ( [[:print:]] ) + printf %s "$key" >> input + ;; + + ( "$(printf '\020')" | "$(printf '\016')" ) # Ctrl-P Ctrl-N + ;; + + ( "$(printf '\033')" | "$(printf '\003')" ) # Escape Ctrl-C + exit 0 + ;; + + ( "$(printf '\015')" ) # Ctrl-M Enter + sed 's/$/\n/' input > in + printf '' > input + ;; + + ( "$(printf '\025')" ) # Ctrl-U + printf '' > input + ;; + + ( "$(printf '\027')" ) # Ctrl-W + sed -i 's/[^ \t]* *$//' input + ;; + + ( "$(printf '\010')" | "$(printf '\177')" ) # Ctrl-H Backspace + sed -i 's/.$//' input + ;; + + ( "$(printf '\014')" ) # Ctrl-L + less out + print_screen + ;; + esac + + print_prompt + done +} + + +# +# Print a prompt with the current input +# +print_prompt() +{ + IFS='' read -r input < input + + size="$(stty -F /dev/tty size)" + width="$((${#input} + 4 - ${size#* }))" + + if [ "$width" -gt 0 ] + then + input="$(printf %s "$input" | cut -c "$width"- | tr -d '\n')" + fi + + printf '\r\033[K> %s' "$input" +} + + +# +# Update the buffer lines and prompt +# +print_screen() +{ + size="$(stty -F /dev/tty size)" + + stty sane + + printf '\033[H\033[J' + [ -f out ] && tail -n "${size#* }" out + print_prompt + + stty raw +} + + +# +# Print lines after formatting them and update the prompt. +# +print_lines() +{ + while IFS='' read -r line + do + printf '\a\r\033[K%s\n' "$line" + print_prompt + done +} + + +main() +{ + trap 'print_screen' WINCH + trap 'stty sane' EXIT + + input +} + + +main "$@" diff --git a/README.sh b/README.sh @@ -1,7 +1,7 @@ case "$1" in -l | link ) # link the dotfiles in this directory +( l | link ) # link the dotfiles in this directory cd "${0%/*}" || exit 1 @@ -15,7 +15,7 @@ l | link ) # link the dotfiles in this directory ;; -g | git ) # my other projects +( g | git ) # my other projects mkdir -p ~/src && cd ~/src || exit @@ -33,7 +33,7 @@ g | git ) # my other projects ;; -b | build ) # package manager +( b | build ) # package manager wget -O - http://github.com/josuah/build/archive/master.tar.gz | tar zxf - && cd build-master || exit @@ -42,7 +42,7 @@ b | build ) # package manager ;; -m | mail ) # setup mail credentials +( m | mail ) # setup mail credentials mkdir -p "$MAIL/cur" "$MAIL/new" "$MAIL/tmp"