diff options
| Commit | dd1159d8a053817b9f89902d6ddff4fce1675894 (patch) | |
|---|---|---|
| Author | 2025-08-20 05:18:37 +0300 | |
| Committer | 2025-08-20 05:18:37 +0300 | |
| Files | 9a81ba5eb250b8fe1b4863a1bed90cfdf5a2c90c /src/blog | |
| syndamia.com-dd1159d8a053817b9f89902d6ddff4fce1675894.tar syndamia.com-dd1159d8a053817b9f89902d6ddff4fce1675894.tar.gz syndamia.com-dd1159d8a053817b9f89902d6ddff4fce1675894.zip | ||
| Parent | 06e6de1d1b31415e513618d4dd79cda348fcc5cf (diff) | |
fix(blog/plan9-in-linux-mouse-menus): Correct code blocks
3 files changed, 120 insertions, 50 deletions
| -rw-r--r-- | src/blog/plan9-in-linux-mouse-menus/index.du | 71 | ||||
| -rw-r--r-- | src/blog/plan9-in-linux-mouse-menus/jgmenurc | 18 | ||||
| -rw-r--r-- | src/blog/plan9-in-linux-mouse-menus/plumb.sh | 81 |
diff --git a/src/blog/plan9-in-linux-mouse-menus/index.du b/src/blog/plan9-in-linux-mouse-menus/index.du index ea1345f..ac2672a 100644 --- a/src/blog/plan9-in-linux-mouse-menus/index.du +++ b/src/blog/plan9-in-linux-mouse-menus/index.du @@ -181,46 +181,25 @@ Unfortunately it always spawns in such a way that the pointer is at the top-left Finally, since I use it as an application menu too, I specify a config file which makes it look more like Plan 9's menu (though I've personally omitted the color scheme, since it doesn't fit my normal theme): -:code -menu_width = 1 -arrow_width = 1 -icon_size = 0 - -menu_radius = 0 -item_radius = 0 - -# Plan 9 color scheme -menu_border = 5 -menu_padding_top = 0 -menu_padding_right = 0 -menu_padding_bottom = 0 -menu_padding_left = 0 -color_menu_bg = #eaffea 100 -color_menu_border = #88cc88 100 -color_norm_fg = #000000 100 -color_sel_bg = #448844 100 -color_sel_fg = #000000 100 - +``` +'include ./jgmenurc More info on these options can be found in the [url https://jgmenu.github.io/jgmenu.1.html manpage]. Putting it all together, it looks something like this: -:code_bash -action=$(echo -ne "Send,echo 1\nResize,echo 2\nMove,echo 3\n" | jgmenu --at-pointer --simple --config-file="$HOME/.config/jgmenu/jgmenusimplerc") - -case "$action" in - 1) ... - ;; - 2 ... +```bash +'snippet 54 54 ./plumb.sh +'snippet 58 59 ./plumb.sh + 1) ... ;; - 3) ... + 2) ... ;; - *) - ... + ... +\ + *) ... ;; -esac - +'snippet 81 $ ./plumb.sh An important aspect of our menu options is that they can change depending on context. For example, if we have a URL we might want the options "Open it in browser" and "Download", which we wouldn't want in case of a .docx file. @@ -231,23 +210,15 @@ My preferred way is to have a variable `[menu]` to which different options are a To work with regular expressions more easily, I've made a function which returns a status code depending on matching. All in all, it would look something like this: -:code_bash -menu="" -windowOptions=0 - -function matches() { - echo "$selection" | grep "$1" >/dev/null 2>&1 -} - -[ windowOptions -eq 1 && menu+="Resize,echo 3\nMove,echo 4\nDelete,echo 5\n,....." -matches ".*\.cpp" && menu+="Compile and run,echo 10\n" - -action=$(echo -ne "$menu" | jgmenu --at-pointer --simple --config-file="$HOME/.config/jgmenu/jgmenusimplerc") - -case "$action" in - ... -esac - +```bash +'snippet 26 26 ./plumb.sh +'snippet 28 38 ./plumb.sh +'snippet 45 46 ./plumb.sh +\ +'snippet 54 54 ./plumb.sh +'snippet 58 59 ./plumb.sh + ... +'snippet 81 $ ./plumb.sh #### #4 @@ -296,7 +267,7 @@ Finally, in our script, we want to read that file, only if we're inside a termin ```bash wname="$(cat /proc/"$pid"/comm)" -if [ $wname == "TERMINAL"; then # Replace with your terminal emulator name +if [ $wname == "TERMINAL" ]; then # Replace with your terminal emulator name xdotool key Control+Alt+Page_Up # Execute the shell-compatible combination sleep 0.1 # Rework with inotify? cd "$(cat /tmp/plumb-cwd)" diff --git a/src/blog/plan9-in-linux-mouse-menus/jgmenurc b/src/blog/plan9-in-linux-mouse-menus/jgmenurc new file mode 100644 index 0000000..bb97010 --- /dev/null +++ b/src/blog/plan9-in-linux-mouse-menus/jgmenurc @@ -0,0 +1,18 @@ +menu_width = 1 +arrow_width = 1 +icon_size = 0 + +menu_radius = 0 +item_radius = 0 + +# Plan 9 scheme +#menu_border = 5 +#menu_padding_top = 0 +#menu_padding_right = 0 +#menu_padding_bottom = 0 +#menu_padding_left = 0 +#color_menu_bg = #eaffea 100 +#color_menu_border = #88cc88 100 +#color_norm_fg = #000000 100 +#color_sel_bg = #448844 100 +#color_sel_fg = #000000 100 diff --git a/src/blog/plan9-in-linux-mouse-menus/plumb.sh b/src/blog/plan9-in-linux-mouse-menus/plumb.sh new file mode 100644 index 0000000..6f42d7c --- /dev/null +++ b/src/blog/plan9-in-linux-mouse-menus/plumb.sh @@ -0,0 +1,81 @@ +#/bin/bash + + +# +# Get selection text and go to window directory +# + +selection="$(xclip -o)" + +# Copied from https://odysee.com/@Luke:7/plumbing-in-linux-la-plan-9-from-bell:e +pid=$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep -m 1 PID | cut -d " " -f 3) +pid1=$(pstree -lpA "$pid" | tail -n 1 | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g') +cd "$(readlink /proc/"$pid1"/cwd)" + +wname="$(cat /proc/"$pid"/comm)" +if [ $wname == "terminator" ]; then + xdotool key Control+Alt+Page_Up + sleep 0.1 + cd "$(cat /tmp/plumb-cwd)" +fi + +# +# Create jgmenu menu +# + +menu="" +if [ -z "$1" ]; then + function matches() { + echo "$selection" | grep "$1" >/dev/null 2>&1 + } + + # Settings, 1 for include in menu, 0 for don't include + plan9=0 + runInTerminal=1 + + # -= Plan 9 functions =- + [ $plan9 -eq 1 ] && menu+="Send,echo 2\nResize,echo 3\nMove,echo 4\n" + + # -= Run =- + if [ $runInTerminal -eq 1 ]; then + [ $wname == "terminator" ] && [ $plan9 -ne 1 ] && menu+="Send,echo 2\n" + [ $wname == "terminator" ] && menu+="Exec,echo 5\n" \ + || menu+="Exec,echo 6\n" + fi + #matches "[[:alnum:]]*" && menu+="Run,echo 2\n" + #matches ".*\.cpp" && menu+="Build and run,echo 2\n" +fi + +# +# Execution menu option +# + +if [ -z "$1" ]; then + action=$(echo -ne "$menu" | jgmenu --at-pointer --simple --config-file="$HOME/.config/jgmenu/jgmenusimplerc") +else + action="1" +fi + +case "$action" in + 1) xdg-open "$selection" + ;; + 2) xdotool type --delay 0 "$selection" + ;; + 3) xdotool keydown Alt + xdotool mousedown 3 + xdotool keyup Alt + ;; + 4) xdotool keydown Alt + xdotool mousedown 1 + xdotool keyup Alt + ;; + 5) terminator --new-tab --command="zsh $selection" & + disown + ;; + 6) terminator --command="$selection" & + disown + ;; + *) + notify-send "Bad action!" + ;; +esac |