diff options
author | cos <cos> | 2022-10-02 23:58:50 +0200 |
---|---|---|
committer | cos <cos> | 2022-10-02 23:58:50 +0200 |
commit | e0330cb6feb7800608186d9374a99a9f6ab5dd63 (patch) | |
tree | c8154189e006c00ef03a30bb4f8efbfaae825787 /lib | |
download | micmot-e0330cb6feb7800608186d9374a99a9f6ab5dd63.zip |
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/micmot-irssi-wrapper | 7 | ||||
-rwxr-xr-x | lib/micmot-menu-pane | 73 | ||||
-rwxr-xr-x | lib/micmot-weechat-wrapper | 7 | ||||
-rw-r--r-- | lib/tmux-micmot.conf | 2 |
4 files changed, 89 insertions, 0 deletions
diff --git a/lib/micmot-irssi-wrapper b/lib/micmot-irssi-wrapper new file mode 100755 index 0000000..60869fe --- /dev/null +++ b/lib/micmot-irssi-wrapper @@ -0,0 +1,7 @@ +#!/bin/sh -eu + +_fifo="${IRSSI_TMUX_FIFO:-${HOME}/.irssi/micmot-fifo}" + +mkfifo "${_fifo}" +tail -f "${_fifo}" & +irssi diff --git a/lib/micmot-menu-pane b/lib/micmot-menu-pane new file mode 100755 index 0000000..0b4900e --- /dev/null +++ b/lib/micmot-menu-pane @@ -0,0 +1,73 @@ +#!/usr/bin/sh -eu + +_script_name='micmot' + +_micmot_menu_i_cmd='micmot-irssi-wrapper irssi' +_micmot_menu_i_desc='Launch irssi as current user' +_micmot_menu_w_cmd='micmot-weechat-wrapper weechat' +_micmot_menu_w_desc='Launch weechat as current user' +_micmot_menu_d_cmd='sudo -u bar WEECHAT_TMUX_PANE=foo + `which micmot-weechat-wrapper` weechat' +_micmot_menu_d_desc='Launch weechat for foo as user bar' + +text_width() { + IFS='' + echo "$@" | while read -r _line; do + echo ${#_line} + done | sort -n | tail -1 + unset IFS +} + +micmot_banner() { + _micmot_banner="$( figlet -f slant "${_script_name}" )" || return 0 + _text_width=$( text_width "$_micmot_banner" ) || return 0 + _terminal_width=$( tput cols ) || return 0 + + _padding=$( printf "%$(( (_terminal_width - _text_width) / 2 ))s" ' ' ) + IFS='' + echo "$_micmot_banner" | while read -r _line; do + echo "${_padding}${_line}" + done + unset IFS + + unset _micmot_banner _terminal_width _text_width +} + +micmot_menu() { + for _menu_option in $( set | sed -n 's/.*_micmot_menu_\(.\)_desc=.*/\1/p' ) + do + printf "%3s %s\n" "${_menu_option}" \ + "$( eval echo \${_micmot_menu_${_menu_option}_desc} )" + done + printf '\n' + printf "%3s %s\n" 'q' "Quit ${_script_name}. (Will not kill other panes)" + printf '\n> ' + unset _menu_option +} + +clear +_input='' +while ( true ); do + printf "\ek${_script_name}\e\\" + printf "\e]2;${_script_name}\e\\" + micmot_banner + micmot_menu + + read -r _input + case "${_input}" in + 'q' | 'Q') + break + ;; + *) + if [ "$( eval echo \${_micmot_menu_${_input}_cmd} 2>/dev/null )" ]; then + echo "Selected: $( eval echo \${_micmot_menu_${_input}_desc} )" + tmux -L "${MICMOT_SOCKET}" \ + new-window "$( eval echo \${_micmot_menu_${_input}_cmd} )" + else + echo "Unknown choice: ${_input}" >&2 + fi + ;; + esac +done + +# vim: sw=2 et diff --git a/lib/micmot-weechat-wrapper b/lib/micmot-weechat-wrapper new file mode 100755 index 0000000..ec18f78 --- /dev/null +++ b/lib/micmot-weechat-wrapper @@ -0,0 +1,7 @@ +#!/bin/sh -eu + +_fifo="${HOME}/.weechat/micmot-fifo" + +mkfifo "${_fifo}" +tail -f "${_fifo}" & +weechat diff --git a/lib/tmux-micmot.conf b/lib/tmux-micmot.conf new file mode 100644 index 0000000..58da856 --- /dev/null +++ b/lib/tmux-micmot.conf @@ -0,0 +1,2 @@ +set-option -g allow-rename on +set-option -g remain-on-exit on |