summaryrefslogtreecommitdiff
path: root/lib/micmot-menu-pane
diff options
context:
space:
mode:
Diffstat (limited to 'lib/micmot-menu-pane')
-rwxr-xr-xlib/micmot-menu-pane73
1 files changed, 73 insertions, 0 deletions
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