dot

packages and services management
Log | Files | Refs | README

commit 4700624c22af77a40faec44bf292c341db31170b
parent b08a22f75f64edcef7961333be34bdaa64843fbf
Author: josuah <mail@josuah.net>
Date:   Tue, 24 Jan 2017 20:22:37 +0100

Fixed ii-client

Diffstat:
A.local/bin/ii-client | 138+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D.local/bin/iirc | 127-------------------------------------------------------------------------------
M.profile | 5++++-
MREADME.sh | 8++++----
4 files changed, 146 insertions(+), 132 deletions(-)

diff --git a/.local/bin/ii-client b/.local/bin/ii-client @@ -0,0 +1,138 @@ +# 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 +} + + +# 1: key to use + +key() +{ + case "$1" in + + ( [[:print:]] ) + printf %s "$key" >> input + ;; + + ( "$(printf '\020')" | "$(printf '\016')" ) # Ctrl-P Ctrl-N + ;; + + ( "$(printf '\033')" | "$(printf '\003')" ) # Escape Ctrl-C + return 1 + ;; + + ( "$(printf '\015')" ) # Ctrl-M Enter + sed 's/$/\n/' input > in + printf '' > input + ;; + + ( "$(printf '\025')" ) # Ctrl-U + printf '' > input + ;; + + ( "$(printf '\027')" ) # Ctrl-W + [ -f input ] && sed -i 's/[^ \t]* *$//' input + ;; + + ( "$(printf '\010')" | "$(printf '\177')" ) # Ctrl-H Backspace + [ -f input ] && sed -i 's/.$//' input + ;; + + ( "$(printf '\014')" ) # Ctrl-L + less out + print_screen + ;; + esac + + print_prompt + + return 0 +} + + +# +# Manage characters typed by user. +# +input() +{ + printf '' > input + + print_prompt + + while key="$(get_char)" + do + key "$key" || break + done +} + + +# +# Print a prompt with the current input +# +print_prompt() +{ + [ -f input ] && 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"-)" + 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 +} + + +main() +{ + trap 'print_screen' WINCH + + print_screen + + (tail -n 0 -f out & printf '%s\n' $! > pid) | while IFS='' read -r line + do + printf '\a\r\033[K%s\n' "$line" + print_prompt + done & + + input + + read pid < pid + rm -f pid input + + kill -9 "$pid" + stty sane +} + + +main "$@" diff --git a/.local/bin/iirc b/.local/bin/iirc @@ -1,127 +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 - 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/.profile b/.profile @@ -54,6 +54,7 @@ alias la='ls -Alhp --color' alias cl='printf "\033[H\033[2J"' alias bh='page busybox --help' alias grep='page grep' +alias ..='cd ..' # iomenu alias a='io-abduco' @@ -61,11 +62,13 @@ alias r='io-run' alias g='io-grep' alias v='io-files' alias m='io-man' -alias i='io-ii' alias f='find ! -path "*/.git/*" -type f | iomenu' alias d='find ! -path "*/.git/*" -type d | iomenu' alias c='cd "$(d)"' +# scripts +alias i='ii-client' + # tmux alias t='tmux attach &>/dev/null || tmux new' diff --git a/README.sh b/README.sh @@ -5,10 +5,10 @@ case "$1" in cd "${0%/*}" || exit 1 - find . -path './.*' ! -path './.git*' | while IFS='' read -r path + find "$PWD" -path "$PWD/.*" ! -path '*/.git*' | while IFS='' read -r path do - [ -d "$path" ] && mkdir -p ~"${path#.}" - [ -f "$path" ] && ln -sf "$path" ~"${path#.}" + [ -d "$path" ] && mkdir -p "$HOME/${path#$PWD/}" + [ -f "$path" ] && ln -sf "$path" "$HOME/${path#$PWD/}" done find -L ~ -type l -exec rm {} \; @@ -37,7 +37,7 @@ case "$1" in wget -O - http://github.com/josuah/build/archive/master.tar.gz | tar zxf - && cd build-master || exit - make PREFIX=~/.local install + make PREFIX="$HOME/.local" install cd .. && rm -rf build-master ;;