To start a program on a buffer, I use slmenu/dmenu that acts like normal dmenu, but allowing to add further arguments to it, include aliases for command I always start the same way, or permit to fuzzy find files right away and pass them as arguments.
[h2]Getting started[/h2]
1. Copy the two following scripts in $PATH
2. Install dmenu as well as vis-menu (coming with the vis editor) or replace vis-menu by dmenu (<code>sed 's/vis-menu/dmenu/g'</code> should work).
3. Enter 'run' in a terminal, you will be prompted for a command to run in an abduco session. The script will start some command with default arguments, like shell aliases, and you can tweak the script to your likings... If no 'alias' is defined, it will prompt you for the arguments. If you enter '*' anywhere, it will prompt you for a file and replace the '*' by this file.
4. To come back to the terminal, press ctrl + z, this will detach abduco.
5. To list the abduco sessions/buffers, write <code>attach</code>, it will prompt you for a buffer to attach to.
You can configure shell aliases in .profile, .bashrc, .zshrc, ... with the following to make it go fast:
Code:
alias r=run
alias a=attach
alias v="run $EDITOR"
[h2]The sources[/h2]
So I made 2 shell scripts for this purpose: one to start a buffer and one to switch to a buffer. I put comments in both files.
<code>~/bin/run</code>:
Code:
#!/bin/sh
# External: stest, vis-menu, abduco
# Busybox: mkdir, tee, sort, clear
NL='
' # Trick to use newline character without breaking identation
cmd="$1" # allow to pass commands: run htop starts htop right away.
# Get or create the cache file: The same as dmenu.
cache="${XDG_CACHE_HOME:-"$HOME/.cache"}"
mkdir -p "$cache"
cache="$cache/dmenu_run"
# Get the command to run using dmenu/vis-menu
printf '\033[1A'
[ -z "$cmd" ] && cmd="$(
IFS=:
if stest -dqr -n "$cache" $PATH
then stest -flx $PATH | sort -u | tee "$cache"
else tee < "$cache"
fi | vis-menu
)"
printf '$ %s ' "$cmd"
# These are sort of aliases: change them to your taste!
# They set the command line options/arguments to use for some commands.
name="$cmd"
case "$cmd" in
'' ) exit 1 ;;
mbsync ) opt='-a' ;;
alsamixer ) opt='-c 1' ;;
ping ) opt='-c 3 www.wikipedia.org' ;;
feeds ) opt='read' ;;
htop | s-nail | irc | rirc | agenda | cmus ) : ;; # These does not have any option.
vi | vim | vis | less ) # These are the commands that only require a file as argument.
opt="$(find ./ -type f | vis-menu -l 10)" file="$opt"
;;
* ) # For all the other commands, prompt the user what to add
read opt
if [ -z "${opt##*\**}" -a "$opt" ] # If the command has a '*', prompt for a file.
then
file="$(find ./ -type f | vis-menu -l 10)"
opt="${opt##*\*} $file ${opt%%\**}"
fi
;;
esac
# Update the name using the file path, if any
if [ "$file" ]
then
file="$PWD/${file#./}"
[ -z "${file##$HOME*}" ] && file="~${file#$HOME}"
file=" $file"
fi
# Start the command in an abduco session
TERM=screen ABDUCO="$cmd" \
abduco -A "$(printf '%s%s' "$cmd" "$file" | tr '/' '!')" $cmd $opt
vis-menu is a slmenu fork that is more maintained (slmenu was inactive for a while), and used in the vis editor. But it is a standalone tool!
stest is a tool used in dmenu to test file properties and get the list of executables.
<code>~/bin/attach</code>:
Code:
#!/bin/sh
# External: abduco, vis-menu
# Busybox: sed
TAB=' ' # Make literal tabs explicit on the code
# If already on a session, print its name and exit
[ "$ABDUCO" ] && printf '[ %s ]\n' "$ABDUCO" | tr '!' '/' && exit 1
printf '\033[1A'
# Get the session name by prompting the user. Workaround for tab error
# of vis-menu (https://github.com/martanne/vis/issues/365)
name="$(abduco \
| sort -t "$TAB" -k 3 \
| tr '!' '/' \
| sed '1d; s/\t/ /g' \
| vis-menu -l 10 \
| tr '/' '!'
)"
name="${name##* }"
# Reset the screen, set the name of the session and attath to it
printf '\033[2J\033[0;0f\033[0m\033]0;%s\007' "$name" | tr '!' '/'
[ "$name" ] && TERM=screen ABDUCO="$name" abduco -a "$name"
# Reminder of current sessions
printf '\n'
abduco | tr '!' '/' | sort -t "$TAB" -k 3 | sed -n '1d; s/^/ /; s/\t/ /g p'
It also uses vis-menu.
If you want to use dmenu, just replace <code>vis-menu</code> by <code>dmenu</code>, and it works right away! As dmenu and vis-menu have the same command-line options.
On the other hand, I am not as good as you for window management (quite no config at all!). So thank you for these tips!
PS: Something like wolfmenu could also be nice to integrate with this.
PS2: If I do not say it, I think fyr will say it: You can also use
dtach instead of abduco, but it uses configure, and the ./configure script is bigger than the whole source of dtach (!). Thank you autotools!
PS3: For updated versions, if any, you can have a look at
this repo
PS4: After I'm done with mountain hiking (1 week), I can provide support for this! And tweak the script for your need if is not too hard... Remember that I'm lazy!
PS5: Because this post was not long enough and did not have enough PSs, I am just adding one.