Your Latest Workflow Improvement - Desktop Customization & Workflow

Users browsing this thread: 29 Guest(s)
z3bra
Grey Hair Nixers
I've been ricing for years as you all probably know. And one thing I've learnt is that you don't rice once and be done with it. There is always something you want to change, something you want to fix, something you grew tired of...

It's a never ending process, or a kindof "drug". So I'm just trying to focus on using my desktop rather than making it usable :)
kirby
Long time nixers
Contrary to the above, I've had the same basic setup (dwm, 1 'primary' colour on a complementary grey, 1px-wide borders) for a good few years now and the exact colourscheme for at least one year. Whenever I go to change anything I always end up deciding I preferred what I had so just go back. I guess I'm just stuck in my ways.

To stay vaguely on topic, I installed an SSD on my netbook so it's a lot quicker, which I guess is a workflow improvement haha.
ninjacharlie
Members
(28-12-2015, 09:28 AM)kirby Wrote: To stay vaguely on topic, I installed an SSD on my netbook so it's a lot quicker, which I guess is a workflow improvement haha.

Which laptop are you using? I've been looking at this one: http://www.amazon.com/gp/product/B00SGS7ZH4 , but am not sure if Linux support is any good.
Pr0Wolf29
Members
I set a keybind for terminal, wolfmenu, and printscreen screenshot.
z3bra
Grey Hair Nixers
What's wolfmenu? A menu for wolfenstein?
Pr0Wolf29
Members
[Image: sc1.png?raw=true]
Some menu program I made. Kinda like dmenu but user-defined and for GUI and terminal usage.
arcetera
Members
i got a second monitor and hacked around to make it work with wmutils
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...
Tmplt
Long time nixers
I often leave the terminal when I want to translate words and phrases to/from a language and also when I want to define a word.. No longer!
Code:
define() {
  curl dict://dict.org/d:$@ | less
}
alias def='define'

translate() {
  dict -d fd-$1-$2 "${@:2}"
}
alias tra='translate'
venam
Administrators
(29-07-2016, 02:38 AM)Tmplt Wrote: I often leave the terminal when I want to translate words and phrases to/from a language and also when I want to define a word.. No longer!
I've ran into the same issue just recently.
I already had a define command but, just like yours it was using the internet to fetch definitions.

After some research, `sdcv` seemed like a good solution.
The archwiki, as usual, was a good place to get information from.
I got the stardict-dictd_www.dict.org_gcide-2.4.2 dictionary.

Now no need for internet to fetch those definitions.
z3bra
Grey Hair Nixers
I use google for that:

Code:
#!/bin/sh

# use the google translate service
# depends: curl

if test -z "$1"; then
    echo "usage: $(basename $0) text"
    echo "examples:"
    echo "    $(basename $0) text"
    echo "    TL=el $(basename $0) text"
    echo "    SL=en TL=pl $(basename $0) text"
    exit 1
fi

TEXT=$1
SL=${SL:-auto}
TL=${TL:-fr}

TRANSLATEURL='https://translate.google.com/'
UA='Mozilla 5.0'
NEWLINE='\
'

# do translate
curl --user-agent "$UA" \
    --data "sl=$SL" \
    --data "tl=$TL" \
    --data-urlencode "text=$TEXT" \
    --silent $TRANSLATEURL \
    | sed "s/<\/span>/$NEWLINE/g" | grep 'result_box' | sed 's/.*>//'

Though it's a bit more complex than yours, it hasn't failed on me yet!
josuah
Long time nixers
tmplt: z3bra: Yet another webservice replaced by a shell script, just like "curl -4 wttr.in"
z3bra
Grey Hair Nixers
Haha, nice! Didn't know about it
Tmplt
Long time nixers
(29-07-2016, 04:16 AM)z3bra Wrote: I use google for that:

Oh, that script will come in handy. Thanks!
b3atr
Registered
(17-08-2015, 09:58 AM)venam Wrote: background processes (ctrl-z) and specific zsh tricks with directories (using pushd).

those are awesome and I couldn't live without them anymore :>

a little bit of URL generating trick to use macmillandictonary.com to get the pronunciation of a word and play it on terminal by mplayer. an alternative would be greatly appreciated :)
Code:
pron() {
    mplayer "$(macmillan:us:api "$1")" > /dev/null 2>&1
}

macmillan:abbreviate() {
    if [[ ${#1} -lt 5 ]]; then
        printf "%s" "${1:0:5}_"
    else
        printf "%s" "${1:0:5}"
    fi
}

macmillan:us:api() {
    local abb=''; abb=$(macmillan:abbreviate "$1")
    local host='http://www.macmillandictionary.com'
    local path="media/american/us_pron/${1:0:1}/${1:0:3}/$abb"
    local filename="${1}_American_English_pronunciation"
    printf "%s/%s/%s.mp3\n" "$host" "$path" "$filename"
}
neeasade
Grey Hair Nixers
> pron() {

that's not where I thought that was going.
Adrift
Members
I'm sure that these are horrible. But I thought I would share a couple scripts that might fit in here.

Earlier in the thread a window selecter had been mentioned, I've been using this for quite some time now.

It depends on wmctrl and wmutils, but you can substitute most of it honestly. Although using wmctrl allows one to see the window id, workspace, and title all at once.

Code:
#!/bin/sh

wids="$(wmctrl -l \
    | sed s/"$HOSTNAME"// | dmenu)" || exit 1

wid=`echo "$wids" | awk '{print $1}'`
#did=`echo "$wids" | awk '{print $2}'` #uncomment for workspaces
#wmctrl -s $did && wtf $wid && chwso -r $wid #uncomment for workspaces
wtf $wid && chwso -r $wid

I also made a conversion script, since units didn't play well with dmenu. But found it gets all of google's quick instant answers, like what time is it in ___ city, country, etc.

Code:
#!/bin/sh

string=$@

string=$( printf "%s\n" "$string" | sed 's/ /%20/g' )

w3m -dump http://www.google.com/search?q=$string | sed -e s/□\|•\|Any time//g -e s/^ *//g -ne 14,15p | dmenu

I also spent quite some time working on a bookmarks dmenu for my firefox and vimb bookmarks, titles display in dmenu, then launch in vimb.

I had to re-enable the creation of bookmarks.html in about:config. And both use an automated a sed command to remove a lot of dumb reformatting.

I don't miss tabs at all, and now use rtv instead of the browser.

Lastly I couldn't survive without the "keyword" function I picked up from firefox, that I use in vimb as "shortcuts" like duckduckgo bangs.

Edited a bunch of times because I forgot shit, then shortened.
josuah
Long time nixers
I am slowly taking the halfwit route, by building up dmenu scripts.

All the io-* scripts in ~/etc/bin/ use iomenu, and I try to keep them stupid.

io-calendar: One line per event, from ical files, converted with calendar-update
Code:
2017/04/20 20:40 - 2017/04/20 21:20  Writing post at nixers.net
2017/04/20 21:21 - 2017/04/20 21:22  Go fix that post
2017/04/20 21:25 - 2017/04/20 21:25  Come back and fix that post again

io-edit: Most recently used files and all files in $HOME
Code:
# recent files
/home/josuah/src/iomenu/iomenu.c
/home/josuah/src/iomenu/Makefile
# all files
/home/josuah/etc/man/build.1
/home/josuah/etc/man/README

io-abduco: prompt to attach/create an abduco(1) session
Code:
Thu    2017-04-20 00:01:31    whatever session name
Mon    2017-04-19 23:59:14    shannon univ project

io-setfont: For setting TTY fonts in linux (BSD has wsconsctl), psf format.
Code:
/home/josuah/etc/consolefonts/drdos-16.psf
/home/josuah/etc/consolefonts/greek-polytonic-16.psf
/home/josuah/etc/consolefonts/inconsolata-16b.psf
/home/josuah/etc/consolefonts/inconsolata-16n.psf
/home/josuah/etc/consolefonts/lode-16.psf
/home/josuah/etc/consolefonts/miniwi-16.psf

io-search: Prompt for a dir and dump the content of every file, for interactive search, and open the selected line of file in editor. iomenu can handle it (strstr(3) can).
Code:
# /path/to/file/1
      1 First line
      2 Second line
      3 Third line
# /path/to/file/2
      1 First line
      2 Second line

io-mblaze: for the super-light mail client mblaze(1) that is a set of command line tools.
Code:
/home/josuah/mail/suckless
/home/josuah/mail/lobsters
/home/josuah/mail/INBOX

io-music: You can select a directory or pick individual songs. Currently mplayer, but you can change it.
Code:
./Jim-Guthrie
./Jim-Guthrie/Sword-and-Sworcery-LP--The-Ballad-of-the-Space-Babies
./Jim-Guthrie/Sword-and-Sworcery-LP--The-Ballad-of-the-Space-Babies/01--Dark-Flute.flac
./Jim-Guthrie/Sword-and-Sworcery-LP--The-Ballad-of-the-Space-Babies/02--Lone-Star.flac
./Jim-Guthrie/Sword-and-Sworcery-LP--The-Ballad-of-the-Space-Babies/03--Doom-Sock.flac
./Jim-Guthrie/Sword-and-Sworcery-LP--The-Ballad-of-the-Space-Babies/04--The-Prettiest-Weed.flac
josuah
Long time nixers
Oh, I forgot the best of them:

io-troll: What's the magic word?
replace iomenu with dmenu if you want
Code:
\ \  `-\//__(*=  (*-.\\---'||__, |||      `-._ ------ |,--------.-- |
  \ `-._(((,__` ,c-).~~))__, |--- | |`-._ -----`-.____// ,===-=== `./
         \ \  `------'||---- |___/- |=-==`-.____/*=  (//__(*=  (*-.\\\
         /\ `-.______, |____/-.____/*=  (*-.\\,__` ,c(((,__` ,c-).~~)))
           `-._ ------ |__/|/ (((,__` ,c-).~~))  `----\ \  `------',--------.       \ \\ \`-.____/^C_/    \ \  `------'|| `-._____\ `-.______, ||
/ ,===-=== `.\ `-.______, |     \ `-.______, |`-._      `-._ ------ ||
[12:08] /home/josuah/ 130 |      `-._ ------ |    `-._/ ,===`-.____//
❯❯ ,__` ,c-).~~)).`-.____/.          `-.____/       \//__(*=  (*-.\\
\ \  `------'||,===-=== `.\                  ,-----(((,__` ,c-).~~))
  \ `-.______, |_(*=  (*-.\\)                / ,===-=\ \  `------'||
     `-._ ------ |------.~~))               //__(*=  (\ `-.______, |
         `-.____/===-=== `.|               (((,__`     `-._ ------ |
           ////__(*=  (*-.\\                \ \  `------'||`-.____/
          (((((,__` ,c-).~~))                \ `-.______, |
         / \ \ \  `------'||                  `-._ ------ |
        //__\ \ `-.______, |                      `-.____/
       (       `-._ ------ |
        \/ ,===-=`-`-.____/          ,--------.
        //__(*=  ,--------.         / ,===-=== `.
       (((,__` ,/ ,===-=== `.      //__(*=  (*-.\\
        \ \  `-//__(*=  (*-.\\    (((,__` ,c-).~~))
         \ `-.(((,__` ,c-).~~))    \ ,--------.'||
          `-._ \ \  `------'||      / ,===-=== `.|
          ,-----\ `-.______, |     //__(,--------.
         / ,     `-._ ------ |    (((,_/ ,===-=== `.
        //__(*=  (*-.`-.____/      \ \//__(*=  (*-.\\
       (((,__` ,c-).~~))\\          \(((,__` ,c-).~~))
        \ \  `------'||~~))          `\ \  `------'||
         \ `-.______, |'||             \ `-.______, |
          `-._ ------ |, |              `-._ ------ |
             ``-.____/-- |                  `-.____/
                 `-.____/
Mafia
Long time nixers
Workflow improvement: USE ACME.
My flow is super hot fire now.
josuah
Long time nixers
This ^. And with the "win" command. You get an interactive shell within the editor.

Presentation from Russ Cox himself.
Mafia
Long time nixers
I hope there isn't anyone using acme without win out there.
z3bra
Grey Hair Nixers
Not using acme, but I'm using more and more sam commands thanks to vis. I must say it is way more powerful and comprehensive than vi's addresses. Once you wrap your head around it, it is pretty nice!

Workfllw wise, well, not much changed. I'm removing more and more fluff everyday, and using bare tools more (eg, default dvtm against 1000 lines .tmux.conf).
r4ndom
Members
I'm more and more writing small scripts using dmenu to do things faster.

For example this beauty, which is a small file explorer using dmenu. For me it is used to open my lecture/exercise slides.
drkhsh
Members
Code:
function up {
    if [[ "$#" < 1 ]]; then
        cd ..
    else
        CDSTR=""
        for i in {1..$1}; do
            CDSTR="../$CDSTR"
        done
        cd $CDSTR
    fi
}

Code:
function extract {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2)  tar xjf $1 ;;
            *.tar.gz)   tar xzf $1 ;;
            *.tar.xz)   tar xvJf $1;;
            *.tar.lzma) tar --lzma xvf $1;;
            *.bz2)      bunzip2 $1 ;;
            *.rar)      unrar x $1 ;;
            *.gz)       gunzip $1 ;;
            *.tar)      tar xf $1 ;;
            *.tbz2)     tar xjf $1 ;;
            *.tgz)      tar xzf $1 ;;
            *.zip)      unzip $1 ;;
            *.Z)        uncompress $1 ;;
            *.7z)       7zr e $1 ;;
            *)          echo "'$1' cannot be extracted via extract()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

Code:
function video {
    mpv --cookies-file=/tmp/cookies.txt $(youtube-dl -g --cookies /tmp/cookies.txt "$1")
}

Code:
alias stopwatch="time cat"
darthlukan
Members
A small thing I did recently that has made things a tiny bit easier on myself is to use ZSH's Vi mode. I spend most of my time at work in various vim sessions with several shells open for performing various tasks (e.g. One specifically for debugging and that's all I do in it, another for file management, etc). It always felt a bit jarring to go from vim to one of my shells and have to use different key bindings for tasks. Well, with Vi mode a lot of that is alleviated and it's made a small improvement to my productivity as I don't have to think as much about key bindings.

Since it will probably come up, here's what's in my ~/.zshrc to distinguish modes at the prompt:

Code:
function ins-mode() { echo "λ" }
function cmd-mode() { echo "Ω" }

function build_prompt() {
    local p
    p=()
    if [[ $UID -eq 0 ]]; then
        p+="%{$fg[yellow]%}⚡"
    else
        p+="%{$fg[green]%}⊡"
    fi
    [[ -n $p ]] && echo "$p"  # Need 'echo' or the color escapes cause errors
}

function TRAPINT() {
    VIM_MODE=$(ins-mode)
    zle && zle reset-prompt
    return $(( 128 + $1 ))
}

function set-prompt() {
    case ${KEYMAP} in
        (vicmd)
            VIM_MODE="%{$fg[red]%}$(cmd-mode)"
            ;;
        (main | viins)
            VIM_MODE="%{$fg[green]%}$(ins-mode)"
            ;;
        (*)
            VIM_MODE="%{$fg[green]%}$(ins-mode)"
            ;;
    esac

    PROMPT=" ${VIM_MODE}%{$reset_color%} $(build_prompt)%{$reset_color%} ❱ "
}

function zle-line-init zle-keymap-select {
  set-prompt
  zle && zle reset-prompt
}

function zle-line-finish {
    VIM_MODE=$(ins-mode)
}

zle -N zle-line-init
zle -N zle-line-finish
zle -N zle-keymap-select

The result looks like the following.

CMD Mode:
Code:
Ω ⊡ ❱

INS Mode:
Code:
λ ⊡ ❱
Github: https://github.com/darthlukan
CRUX Ports: http://ports.brianctomlinson.com
GPG: 3694569D
"We're all human, act accordingly." -- Me
jvarg
Members
I guess i'm the only one who does not knew this but
getting some output from a shell command into vim with that little command:

Code:
:r !shellcommand

just blew my mind.
That's so nice :D
z3bra
Grey Hair Nixers
(03-05-2017, 06:21 PM)jvarg Wrote: I guess i'm the only one who does not knew this but
getting some output from a shell command into vim with that little command:

Code:
:r !shellcommand

just blew my mind.
That's so nice :D

Then you'll probably love piping your selection into random programs
Code:
:'<,'>!tr a-z A-Z
venam
Administrators
(04-05-2017, 05:39 PM)z3bra Wrote: Then you'll probably love piping your selection into random programs
Code:
:'<,'>!tr a-z A-Z
My favorite one:
Code:
:'<,'> !fmt
jvarg
Members
(05-05-2017, 12:42 AM)venam Wrote:
(04-05-2017, 05:39 PM)z3bra Wrote: Then you'll probably love piping your selection into random programs
Code:
:'<,'>!tr a-z A-Z
My favorite one:
Code:
:'<,'> !fmt

Oh yes, 10/10 thanks guys!!