Your Latest Workflow Improvement - Desktop Customization & Workflow

Users browsing this thread: 4 Guest(s)
josuah
Long time nixers
I just found a way to bring Emacs-like buffer to the terminal: In emacs, everything is hold into a 'buffer', that can be a file, a terminal app, a process list, a music player, another file, a graphical web browser, a shell, a pdf document, the pdf source file in markdown...

[Image: emacs_ibuffer.png]
iBuffers in Emacs.

This permits you to switch from file to music player to mail client and back to file, with a same interface showing 'everything that is going on' at glance. That was not present outside emacs AFAIK: tmux and dvtm manage "workspaces", "tags", "windows" and "panes", but not "buffers".

Abduco can bring the required abstraction needed to do this: all terminal are wrapped in a nohup for interactive programs (tmux attach/detach feature), and can be detached, list running abduco sessions... And to expose vim buffers to abduco, I simply do not use vim buffers: I start the editor once for every file I edit.

To quickly switch between the buffers, I use slmenu/dmenu to list and select opened buffers. Ctrl + Z comes back from a buffer to the parent shell.

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.
Latest version below...


Messages In This Thread
Your Latest Workflow Improvement - by z3bra - 17-08-2015, 07:50 AM
RE: You latest workflow improvement - by venam - 17-08-2015, 09:58 AM
RE: You latest workflow improvement - by z3bra - 17-08-2015, 11:50 AM
RE: Your latest workflow improvement - by venam - 17-08-2015, 01:56 PM
RE: Your latest workflow improvement - by dkeg - 17-08-2015, 10:56 PM
RE: Your latest workflow improvement - by swathe - 17-08-2015, 11:14 PM
RE: Your latest workflow improvement - by z3bra - 18-08-2015, 04:51 AM
RE: Your latest workflow improvement - by dkeg - 18-08-2015, 07:18 AM
RE: Your latest workflow improvement - by z3bra - 19-08-2015, 12:00 PM
RE: Your latest workflow improvement - by October - 24-08-2015, 07:04 PM
RE: Your latest workflow improvement - by jvarg - 25-08-2015, 04:06 AM
RE: Your latest workflow improvement - by vedard - 29-08-2015, 01:50 PM
RE: Your latest workflow improvement - by swathe - 31-08-2015, 02:17 AM
RE: Your latest workflow improvement - by greduan - 06-09-2015, 10:12 PM
RE: Your latest workflow improvement - by z3bra - 07-09-2015, 04:55 AM
RE: Your latest workflow improvement - by jury - 07-09-2015, 03:15 PM
RE: Your latest workflow improvement - by greduan - 09-09-2015, 11:46 AM
RE: Your latest workflow improvement - by z3bra - 09-09-2015, 01:45 PM
RE: Your latest workflow improvement - by dkeg - 13-09-2015, 06:24 PM
RE: Your latest workflow improvement - by venam - 14-09-2015, 02:06 PM
RE: Your latest workflow improvement - by dkeg - 14-09-2015, 09:23 PM
RE: Your latest workflow improvement - by ashen - 15-09-2015, 02:14 PM
RE: Your latest workflow improvement - by fraun - 21-10-2015, 10:54 AM
RE: Your latest workflow improvement - by fraun - 26-10-2015, 12:46 PM
RE: Your latest workflow improvement - by xero - 28-10-2015, 02:36 PM
RE: Your latest workflow improvement - by z3bra - 28-10-2015, 03:01 PM
RE: Your latest workflow improvement - by xero - 28-10-2015, 03:28 PM
RE: Your latest workflow improvement - by movq - 28-10-2015, 05:36 PM
RE: Your latest workflow improvement - by venam - 29-10-2015, 01:45 AM
RE: Your latest workflow improvement - by z3bra - 29-10-2015, 07:28 AM
RE: Your latest workflow improvement - by movq - 29-10-2015, 12:32 PM
RE: Your latest workflow improvement - by z3bra - 29-10-2015, 03:43 PM
RE: Your latest workflow improvement - by xero - 27-11-2015, 12:01 PM
RE: Your latest workflow improvement - by xero - 30-11-2015, 12:05 PM
RE: Your latest workflow improvement - by apk - 30-11-2015, 02:26 PM
RE: Your latest workflow improvement - by z3bra - 14-12-2015, 07:26 AM
RE: Your latest workflow improvement - by xero - 27-12-2015, 07:48 PM
RE: Your latest workflow improvement - by apk - 27-12-2015, 10:51 PM
RE: Your latest workflow improvement - by venam - 28-12-2015, 01:38 AM
RE: Your latest workflow improvement - by z3bra - 28-12-2015, 04:27 AM
RE: Your latest workflow improvement - by kirby - 28-12-2015, 09:28 AM
RE: Your latest workflow improvement - by z3bra - 25-01-2016, 01:17 PM
RE: Your latest workflow improvement - by josuah - 28-07-2016, 09:32 PM
RE: Your latest workflow improvement - by Tmplt - 29-07-2016, 02:38 AM
RE: Your latest workflow improvement - by venam - 29-07-2016, 02:55 AM
RE: Your latest workflow improvement - by z3bra - 29-07-2016, 04:16 AM
RE: Your latest workflow improvement - by josuah - 29-07-2016, 06:44 AM
RE: Your latest workflow improvement - by z3bra - 29-07-2016, 06:46 AM
RE: Your latest workflow improvement - by Tmplt - 30-07-2016, 06:51 PM
RE: Your latest workflow improvement - by b3atr - 03-08-2016, 05:10 PM
RE: Your latest workflow improvement - by Adrift - 20-02-2017, 08:51 PM
RE: Your Latest Workflow Improvement - by josuah - 19-04-2017, 08:14 PM
RE: Your Latest Workflow Improvement - by josuah - 20-04-2017, 06:41 AM
RE: Your Latest Workflow Improvement - by Mafia - 21-04-2017, 02:08 PM
RE: Your Latest Workflow Improvement - by josuah - 21-04-2017, 02:41 PM
RE: Your Latest Workflow Improvement - by Mafia - 21-04-2017, 04:26 PM
RE: Your Latest Workflow Improvement - by z3bra - 21-04-2017, 06:53 PM
RE: Your Latest Workflow Improvement - by r4ndom - 25-04-2017, 05:59 AM
RE: Your Latest Workflow Improvement - by drkhsh - 28-04-2017, 07:44 PM
RE: Your Latest Workflow Improvement - by jvarg - 03-05-2017, 06:21 PM
RE: Your Latest Workflow Improvement - by z3bra - 04-05-2017, 05:39 PM
RE: Your Latest Workflow Improvement - by venam - 05-05-2017, 12:42 AM
RE: Your Latest Workflow Improvement - by jvarg - 05-05-2017, 03:52 AM
RE: Your Latest Workflow Improvement - by z3bra - 11-06-2017, 07:31 AM
RE: Your Latest Workflow Improvement - by xcko - 12-06-2017, 10:38 PM
RE: Your Latest Workflow Improvement - by z3bra - 13-06-2017, 09:33 AM
RE: Your Latest Workflow Improvement - by gaak - 31-12-2018, 02:06 AM
RE: Your Latest Workflow Improvement - by prx* - 02-01-2019, 02:14 PM
RE: Your Latest Workflow Improvement - by gaak - 02-01-2019, 09:33 PM
RE: Your Latest Workflow Improvement - by anthk - 09-01-2019, 07:24 PM
RE: Your Latest Workflow Improvement - by prx* - 22-02-2019, 07:58 AM
RE: Your Latest Workflow Improvement - by venam - 27-02-2019, 06:20 AM
RE: Your Latest Workflow Improvement - by z3bra - 27-02-2019, 11:40 AM
RE: Your Latest Workflow Improvement - by grah - 16-03-2019, 06:22 PM
RE: Your Latest Workflow Improvement - by Igrom - 18-03-2019, 11:52 AM
RE: Your Latest Workflow Improvement - by wolf - 28-03-2019, 02:36 PM
RE: Your Latest Workflow Improvement - by prx* - 30-03-2019, 09:49 AM
RE: Your Latest Workflow Improvement - by wolf - 31-03-2019, 06:01 PM
RE: Your Latest Workflow Improvement - by z3bra - 31-03-2019, 07:05 PM
RE: Your Latest Workflow Improvement - by pkal - 01-04-2019, 09:55 AM
RE: Your Latest Workflow Improvement - by fraun - 05-04-2019, 11:37 AM
RE: Your Latest Workflow Improvement - by z3bra - 05-04-2019, 02:24 PM
RE: Your Latest Workflow Improvement - by pkal - 12-04-2019, 02:08 AM
RE: Your Latest Workflow Improvement - by z3bra - 12-04-2019, 10:57 AM
RE: Your Latest Workflow Improvement - by acg - 12-04-2019, 01:40 PM
RE: Your Latest Workflow Improvement - by z3bra - 12-04-2019, 02:03 PM
RE: Your Latest Workflow Improvement - by prx* - 16-04-2019, 05:29 AM
RE: Your Latest Workflow Improvement - by z3bra - 16-04-2019, 05:57 AM
RE: Your Latest Workflow Improvement - by venam - 16-04-2019, 06:16 AM
RE: Your Latest Workflow Improvement - by prx* - 16-04-2019, 11:00 AM
RE: Your Latest Workflow Improvement - by prx* - 16-04-2019, 11:00 AM
RE: Your Latest Workflow Improvement - by z3bra - 16-04-2019, 07:03 PM
RE: Your Latest Workflow Improvement - by prx* - 19-04-2019, 04:26 AM
RE: Your Latest Workflow Improvement - by z3bra - 19-04-2019, 07:26 AM
RE: Your Latest Workflow Improvement - by mrtn - 25-04-2019, 04:32 AM
RE: Your Latest Workflow Improvement - by z3bra - 25-04-2019, 08:45 AM
RE: Your Latest Workflow Improvement - by mrtn - 25-04-2019, 10:11 AM
RE: Your Latest Workflow Improvement - by wolf - 22-05-2019, 10:13 PM
RE: Your Latest Workflow Improvement - by z3bra - 23-05-2019, 03:48 AM
RE: Your Latest Workflow Improvement - by Doom - 24-05-2019, 06:56 PM
RE: Your Latest Workflow Improvement - by prx* - 25-05-2019, 02:10 AM
RE: Your Latest Workflow Improvement - by tudurom - 25-05-2019, 05:35 PM
RE: Your Latest Workflow Improvement - by budRich - 26-05-2019, 06:59 AM
RE: Your Latest Workflow Improvement - by Doom - 28-05-2019, 05:27 PM
RE: Your Latest Workflow Improvement - by z3bra - 29-05-2019, 10:46 AM
RE: Your Latest Workflow Improvement - by piotr - 28-06-2019, 02:02 PM
RE: Your Latest Workflow Improvement - by Saos - 29-06-2019, 01:43 PM
RE: Your Latest Workflow Improvement - by wolf - 16-07-2019, 06:53 PM
RE: Your Latest Workflow Improvement - by jkl - 18-07-2019, 04:35 PM
RE: Your Latest Workflow Improvement - by wolf - 22-07-2019, 05:48 PM
RE: Your Latest Workflow Improvement - by jkl - 22-07-2019, 06:00 PM
RE: Your Latest Workflow Improvement - by z3bra - 22-07-2019, 07:14 PM
RE: Your Latest Workflow Improvement - by jkl - 22-07-2019, 10:06 PM
RE: Your Latest Workflow Improvement - by pkal - 23-07-2019, 10:01 AM
RE: Your Latest Workflow Improvement - by jkl - 23-07-2019, 11:30 AM
RE: Your Latest Workflow Improvement - by Halfwit - 24-07-2019, 11:49 PM
RE: Your Latest Workflow Improvement - by anthk - 18-11-2019, 08:51 PM
RE: Your Latest Workflow Improvement - by venam - 10-05-2021, 02:13 AM
RE: Your Latest Workflow Improvement - by s0kx - 10-05-2021, 02:27 AM
RE: Your Latest Workflow Improvement - by seninha - 10-05-2021, 09:24 AM
RE: Your Latest Workflow Improvement - by freem - 11-05-2021, 08:56 AM
RE: Your Latest Workflow Improvement - by dany74q - 23-06-2021, 05:42 PM
RE: Your Latest Workflow Improvement - by jkl - 30-06-2021, 10:30 AM
RE: Your Latest Workflow Improvement - by dany74q - 30-06-2021, 05:46 PM
RE: Your Latest Workflow Improvement - by jkl - 30-06-2021, 06:31 PM
RE: Your Latest Workflow Improvement - by freem - 26-08-2021, 07:48 PM
RE: Your Latest Workflow Improvement - by seninha - 18-02-2022, 09:51 AM
RE: Your Latest Workflow Improvement - by pfr - 25-02-2022, 12:30 AM