summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2024-10-24 22:54:21 +0900
committerA Farzat <a@farzat.xyz>2024-11-04 22:54:21 +0900
commitc68ac8e8d7524dcb448b7970ab7dacef93c47a4a (patch)
tree87d18ff1e684ea74309c045cfa07e9272b7cfb5d /bin
parent4c457acbd55c6e935f822a1c7208f8a53f248beb (diff)
downloaddotfiles-c68ac8e8d7524dcb448b7970ab7dacef93c47a4a.tar.gz
dotfiles-c68ac8e8d7524dcb448b7970ab7dacef93c47a4a.zip
Add some dmenu scripts
Diffstat (limited to 'bin')
-rwxr-xr-xbin/dmenu/dmenu_type70
-rwxr-xr-xbin/dmenu/dmenupass5
-rwxr-xr-xbin/dmenu/terminal_tmux23
-rwxr-xr-xbin/dmenu/tmux_umpv19
4 files changed, 117 insertions, 0 deletions
diff --git a/bin/dmenu/dmenu_type b/bin/dmenu/dmenu_type
new file mode 100755
index 0000000..f9d0346
--- /dev/null
+++ b/bin/dmenu/dmenu_type
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+
+[ -d "$XDG_CACHE_HOME/dmenu_type" ] || mkdir -p "$XDG_CACHE_HOME/dmenu_type"
+[ -f "$XDG_CACHE_HOME/dmenu_type/output" ] || echo xdot > "$XDG_CACHE_HOME/dmenu_type/output"
+[ -f "$XDG_CACHE_HOME/dmenu_type/lang" ] || echo jap_full > "$XDG_CACHE_HOME/dmenu_type/lang"
+
+output="$(cat "$XDG_CACHE_HOME/dmenu_type/output")"
+lang="$(cat "$XDG_CACHE_HOME/dmenu_type/lang")"
+LINES=15
+
+while getopts b:o:l: OPTION
+do
+ case $OPTION in
+ b)
+ buffer="$OPTARG"
+ ;;
+ o)
+ output="$OPTARG"
+ ;;
+ l)
+ lang="$OPTARG"
+ ;;
+ *)
+ exit 1
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+[ "$1" = "set" ] && case "$(printf "lang\nout" | dmenu -p "Choose setting to set:")" in
+ lang)
+ lang="$(printf "emoji\narabic\njap_full\n" | dmenu -p "Set language:")"
+ [ -n "$lang" ] && printf "%s\n" "$lang" > "$XDG_CACHE_HOME/dmenu_type/lang"
+ exit
+ ;;
+ out)
+ output="$(printf "xdot\nclip\nxdotbuff\n" | dmenu -p "Set dmenu_type output:")"
+ [ -n "$output" ] && printf "%s\n" "$output" > "$XDG_CACHE_HOME/dmenu_type/output"
+ exit
+ ;;
+ *)
+ exit 1
+esac
+
+DIC_DIR="$HOME/bin/experimentation/generated/dic_dir"
+
+case "$lang" in
+ jap_full)
+ rows="$(awk '!a[$0]++' "$DIC_DIR"/{hiragana,katakana,kanji,jp_special,double_eng})"
+ get_text () {
+ printf "%s" "$rows" | dmenu -p "$buffer" -l $LINES | cut -f2- -d ' '
+ }
+ ;;
+ emoji)
+ get_text () {
+ awk -F '# ' '/^[^#].*; fully-qualified *#/ {print $2}' "$DIC_DIR/emoji-test.txt" | dmenu -l $LINES | awk '{print $1}'
+ }
+ ;;
+ *)
+ exit
+ ;;
+esac
+
+while text="$(get_text)"; [ -n "$text" ]
+do
+ [ "$output" = "xdot" ] && xdotool type "$text"
+ [ "$output" = "clip" ] || [ "$output" = "xdotbuff" ] && buffer="$buffer$text"
+done
+[ "$output" = "xdotbuff" ] && xdotool type --delay 200 "$buffer"
+[ "$output" = "clip" ] && printf %s "$buffer" | xclip -sel clip
diff --git a/bin/dmenu/dmenupass b/bin/dmenu/dmenupass
new file mode 100755
index 0000000..34b280f
--- /dev/null
+++ b/bin/dmenu/dmenupass
@@ -0,0 +1,5 @@
+#!/usr/bin/env sh
+
+# Get a password using dmenu.
+
+dmenu -P -p "$1"
diff --git a/bin/dmenu/terminal_tmux b/bin/dmenu/terminal_tmux
new file mode 100755
index 0000000..550167f
--- /dev/null
+++ b/bin/dmenu/terminal_tmux
@@ -0,0 +1,23 @@
+#!/usr/bin/env sh
+
+# A script to open a terminal emulator with a tmux session attached.
+# The session name can be supplied, otherwise it is chosen using dmenu.
+# If the chosen option is listed as a session, that session is attached.
+# If the chosen option is not listed, a new session with that name is created.
+
+# The default terminal is st.
+TERMINAL="${TERMINAL:-st}"
+
+if [ -n "$1" ]; then
+ chosen="$1"
+else
+ chosen="$(tmux list-sessions -F \#\{session_name\} | dmenu -p "Choose which tmux session to use")"
+fi
+
+[ -z "$chosen" ] && exit
+
+if tmux has-session -t "$chosen"; then
+ exec $TERMINAL -T "tmux: $chosen" zshrc tmux attach -t "$chosen"
+else
+ exec $TERMINAL -T "tmux: $chosen" zshrc tmux new -s "$chosen"
+fi
diff --git a/bin/dmenu/tmux_umpv b/bin/dmenu/tmux_umpv
new file mode 100755
index 0000000..eb2b4e6
--- /dev/null
+++ b/bin/dmenu/tmux_umpv
@@ -0,0 +1,19 @@
+#!/usr/bin/env sh
+
+# Open links using mpv in a new tmux window while setting the socket name to selection.
+# If the chosen socket is already active, load the urls to the mpv instance instead.
+# Make sure the urls are printed as they are added.
+
+sock_dir="${MPV_SOCKET_DIR:-$XDG_RUNTIME_DIR/mpv/sockets}"
+[ -d "$sock_dir" ] || mkdir -p "$sock_dir"
+sock="$(find "$sock_dir" -maxdepth 1 -mindepth 1 -type s -printf "%f\n" | dmenu -p "Choose mpv instance:")"
+[ -z "$sock" ] && exit 1
+
+if printf '{ "command": ["get_property", "path"] }\n' | nc -NU "$sock_dir/$sock" >/dev/null 2>&1; then
+ for link in "$@"; do
+ [ -e "$link" ] && link="$(realpath -s "$link")"
+ jq -cn --arg l "$link" '{"command":["loadfile",($l),"append"]},{"command":["print-text","LOADFILE:= "+($l)]}'
+ done | nc -NU "$sock_dir/$sock" >/dev/null
+else
+ tmux neww -t mpv: mpv --volume=50 --script-opts=mpv_socket="$sock",print_filenames=yes "$@"
+fi