You are not logged in.

#226 2014-01-29 06:03:47

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Dmenu Hacking Thread

Is it an idea to create a repo on Github to maintain all dmenu scripts and create a dmenu_scripts package for the AUR, containing all updated/maintained scripts?

This thread is a great resource but overview and maintenance is extremely tough.

Offline

#227 2014-01-31 12:42:28

AnSnarkista
Member
Registered: 2013-04-17
Posts: 14

Re: Dmenu Hacking Thread

skanky wrote:
AnSnarkista wrote:

I am using dmenu_recent and I think is awesome! But I don't understand the difference between "terminal" and "terminal_hold", and it is maybe because I have changed the terminal to lxterminal, and something is wrong there. I don't have any skills on scripting, I am trying changing code in a VBox...but I can't get the point.

Thanks a lot for that script!

terminal_hold doesn't close the terminal window when the application ends - terminal on its own will close when the application ends.

This is what I thought in the begining, but it does'nt works for me.

For example, I try to do a yaourt -Syua, but the terminal opens, and then, get closed so fast, no time to see what's happening. I have tried so many changes, and no working.

The most working experiment has been changing:

terminal="lxterminal"
[...]
[[ "$type" = "terminal" ]] && exec $terminal -e "$cmd"
[[ "$type" = "terminal_hold" ]] && exec $terminal -e "$cmd && echo "Press Enter to kill me...""

And both options goes the same way, both works, but when the command is finished, the terminal, goes away (tried with sudo "pacman -Syu" and "yaourt -Syua", I don't know if this info is important)

Then, I have changed the last option, to include the final && read line:

[[ "$type" = "terminal_hold" ]] && exec $terminal -e "$cmd && echo "Press Enter to kill me..." && read line"

And no change...

What's wrong?

And I think I have found something I don't know If it is correct or not while doing those experiments. If I run a command, that command is removed from the "~/.cache/dmenu_recent/All" list, but If you remove that command from the other lists (~/.cache/dmenu_recent/recents, or the .config ones), that command doesn't appear again on the "All" list, so you are not able to run again that command unless you remove all that files or get them empty.

I'll keep working on how can I make use of terminal_hold option properly with lxterminal


Thanks a lot!!

Offline

#228 2014-01-31 14:02:40

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Dmenu Hacking Thread

Yes, you're right it doesn't work - shows how often I use that option.
This is because of the use of && as the echo and read line parts only get executed if the initial command returns the equivalent of true.
Try changing the && to ; as in my tests that works for me. It means that the echo and read will always get executed.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#229 2014-02-01 20:51:47

AnSnarkista
Member
Registered: 2013-04-17
Posts: 14

Re: Dmenu Hacking Thread

skanky wrote:

Yes, you're right it doesn't work - shows how often I use that option.
This is because of the use of && as the echo and read line parts only get executed if the initial command returns the equivalent of true.
Try changing the && to ; as in my tests that works for me. It means that the echo and read will always get executed.

Thanks for your tip, but I have tried to change both &&, only the first one, and only the second one....but none of them works... can you paste your last line?

Thanks a lot!

Offline

#230 2014-02-01 21:16:59

cris9288
Member
Registered: 2013-01-07
Posts: 348

Re: Dmenu Hacking Thread

quick little script to open up a dwb quickmark with dmenu

#!/bin/bash

if [ -f $HOME/.dmenurc ]; then
   source $HOME/.dmenurc
else
   DMENU="dmenu -i"
fi

DMENU="$DMENU -p 'Quickmarks:' -w 400"
QUICKMARKS=/home/christian/.config/dwb/default/quickmarks

GOTO=$(cat $QUICKMARKS | awk '{print $1}' | eval $DMENU)

if [ $? -eq 0 ]; then
   exec dwb $(cat $QUICKMARKS | grep "$GOTO" | awk '{print $2}')
fi

Offline

#231 2014-02-01 21:27:02

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Dmenu Hacking Thread

AnSnarkista wrote:
skanky wrote:

Yes, you're right it doesn't work - shows how often I use that option.
This is because of the use of && as the echo and read line parts only get executed if the initial command returns the equivalent of true.
Try changing the && to ; as in my tests that works for me. It means that the echo and read will always get executed.

Thanks for your tip, but I have tried to change both &&, only the first one, and only the second one....but none of them works... can you paste your last line?

Thanks a lot!

Here it is:

[[ "$type" = "terminal_hold" ]] &&
    exec $terminal sh -c "$cmd ; echo Press Enter to kill me... && read line"

I've just double checked it too.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#232 2014-02-02 00:02:01

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: Dmenu Hacking Thread

for those who are interested. simpleswitcher-dd-git in aur now has a -dmenu switch, which makes it 100% compatible with dmenu.

its a really nice piece of software.

here a little video showing it in action with some custom scripts:
http://files.53280.de/vid/20140201194126.webm


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#233 2014-02-02 11:37:42

sekret
Member
Registered: 2013-07-22
Posts: 283

Re: Dmenu Hacking Thread

skanky wrote:
[[ "$type" = "terminal_hold" ]] &&
    exec $terminal sh -c "$cmd ; echo Press Enter to kill me... && read line"

Thanks for this!

I have a little addition, maybe some of you find this useful:

[...]
known_types=" background terminal terminal_hold terminal_less sudo_background sudo_terminal sudo_terminal_hold sudo_terminal_less "
[...]
[[ "$type" = "background" ]] && exec "$cmd"
[[ "$type" = "terminal" ]] && exec $terminal -t "$cmd" -e "$cmd"
[[ "$type" = "terminal_hold" ]] && exec $terminal -t "$cmd" -e sh -c "$cmd ; echo Press Enter to kill me... && read line"
[[ "$type" = "terminal_less" ]] && exec $terminal -t "$cmd" -e sh -c "$cmd | less"
[[ "$type" = "sudo_background" ]] && exec sudo -i -A "$cmd"
[[ "$type" = "sudo_terminal" ]] && exec $terminal -t "root: $cmd" -e sudo -i -A "$cmd"
[[ "$type" = "sudo_terminal_hold" ]] && exec $terminal -t "root: $cmd" -e sh -c "sudo -i -A $cmd ; echo Press Enter to kill me... && read line"
[[ "$type" = "sudo_terminal_less" ]] && exec $terminal -t "root: $cmd" -e sh -c "sudo -i -A $cmd | less"

(my terminal is st, so I have to do this a little different, but I think you get the idea)

In order to make "sudo -A" work, I have set this variable

export SUDO_ASKPASS="/usr/local/bin/dmenu-sudo"

and here's what dmenu-sudo looks like

#! /bin/sh
dmenu -nf red -nb red -sf red -sb black <&-
echo

Just type your sudo password and enter. A quite nice replacement for stuff like gksudo imo.

Last edited by sekret (2014-02-02 11:51:25)

Offline

#234 2014-02-02 21:09:52

AnSnarkista
Member
Registered: 2013-04-17
Posts: 14

Re: Dmenu Hacking Thread

skanky wrote:
AnSnarkista wrote:
skanky wrote:

Yes, you're right it doesn't work - shows how often I use that option.
This is because of the use of && as the echo and read line parts only get executed if the initial command returns the equivalent of true.
Try changing the && to ; as in my tests that works for me. It means that the echo and read will always get executed.

Thanks for your tip, but I have tried to change both &&, only the first one, and only the second one....but none of them works... can you paste your last line?

Thanks a lot!

Here it is:

[[ "$type" = "terminal_hold" ]] &&
    exec $terminal sh -c "$cmd ; echo Press Enter to kill me... && read line"

I've just double checked it too.

It is still not working for me, and I think it is a lxterminal misconfiguration issue...but thanks for all!

Offline

#235 2014-02-02 21:40:29

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Dmenu Hacking Thread

AnSnarkista wrote:
skanky wrote:
AnSnarkista wrote:

Thanks for your tip, but I have tried to change both &&, only the first one, and only the second one....but none of them works... can you paste your last line?

Thanks a lot!

Here it is:

[[ "$type" = "terminal_hold" ]] &&
    exec $terminal sh -c "$cmd ; echo Press Enter to kill me... && read line"

I've just double checked it too.

It is still not working for me, and I think it is a lxterminal misconfiguration issue...but thanks for all!


Just realised that $terminal is

urxvtc -e

I don't have lxterminal, but I do have termite, which is also a VTE based one.
I tried a few things and, from the command line and there is odd behaviour when using exec with it. May or may not be related.
termite has a --hold option which will do this, if you're happy to move to another VTE based one.

@sekret - looks like a good idea.
I use the default ASKPASS provider, which I quite like, but that's an interesting idea.

Last edited by skanky (2014-02-02 21:44:00)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#236 2014-02-02 22:59:18

Earnestly
Member
Registered: 2011-08-18
Posts: 805

Re: Dmenu Hacking Thread

Synopsis: Stream twitch via livestreamer using dmenu for selection.

I figured I'd share some of the stuff I've done with dmenu.

This script I like to call "ditch" as a play on the website it wraps, "twitch".

This pulls down the twitch.tv API and uses the excellent jshon to intelligently inspect and extract the json I'm interested in.
It then produces a dmenu which lets you pick a stream and run it via livestreamer.

The code (github)

#!/bin/bash
# ~/.local/bin/ditch
# Create a dmenu using the twitch team and stream api

# List of teams or streamers from twitch.tv for inclusion.  curl will pull down
# the json data simultaneously.  (Be careful with too many elements, each
# element is either a `t:` or `s:`)

# t: = twitch team name
# s: = twitch stream names seperated by commas (limit: 25, max: 100.  Add 
#      `&limit=100` to raise this.)
twitch_list=(t:srl t:sda t:csgopros
             s:fatzke,lukerf44,tirean,justshanz,misterpost,eidgod,ultimaomega07)

# Stream quality, each will be attempted in order and falls back to the next
stream_quality="medium,high,best,source"

# Options passed to dmenu, the `-p` prompt is passed later
dmenu_opts=(-fn "Dina Bold 8" -i -l 40)

# Make sure to not (-u) 'unstring' the title as it may contain valid escapes
# which break the strict ordering requirements for the while read loop.  We will
# manually de-string the titles later.
jshon_team_opts=(-e channels -a -e channel -e name -upe link -upe title)

# Arguments required for the steam API
jshon_stream_opts=(-e streams -a -e channel -e name -upe url -upe game)

function get_json {
    local s="$1"

    if [[ "$s" = t:* ]]; then # team
        curl -s "http://api.twitch.tv/api/team/${s#*:}/live_channels.json"
    elif [[ "$s" = s:* ]]; then # stream
        curl -s "https://api.twitch.tv/kraken/streams?channel=${s#*:}"
    fi
}

# Generate an associative array where the key is the team and the value is the
# url to the twitch team api for that team.
declare -A json
for i in "${twitch_list[@]}"; do
    json["$i"]=$(get_json "$i" &)
done

# First line is always the streamer's name, followed by the url and then the
# streamer's title
declare -A streams
while {
    read -r name
    read -r url
    read -r title
}; do
    # Manually de-quote the title and remove backslashes
    title="${title%\"*}" title="${title#\"}" title="${title//\\/}"

    # Store the name and title for dmenu to display as the key in an associative
    # array where the url is the value.
    if [[ "$name" != http* ]]; then
        streams["$title ($name)"]="$url"
    fi
done < <(
    for i in "${!json[@]}"; do
        if [[ "$i" = t:* ]]; then
            jshon "${jshon_team_opts[@]}" <<< "${json[$i]}"
        elif [[ "$i" = s:* ]]; then
            jshon "${jshon_stream_opts[@]}" <<< "${json[$i]}"
        fi
    done
)

# Display the number of current streams in dmenu's prompt
nstreams="${#streams[@]}"
dmenu_opts+=(-p "Streams ($nstreams)")

# Display the keys and store it as the selection
if sel=$(printf "%s\n" "${!streams[@]}" | sort | dmenu "${dmenu_opts[@]}"); then
    lstreamer_opts=(
        # Strip out any single quotes from the title, this is ugly though, very ugly.
        -Q -p "mpv --force-window --really-quiet --title='${sel//\'/’}' --profile=live"
        --ringbuffer-size 800000 "${streams[$sel]}" "$stream_quality"
    )

    # Pass the value based on the key from selection to livestreamer
    if ! livestreamer "${lstreamer_opts[@]}"; then
        if hash i3-nagbar; then
            i3-nagbar -m "Failed: ${streams[$sel]} ($?)" -t error
        else
            printf >&2 "Failed: %s (%d)" "${streams[$sel]}" "$?"
        fi
    fi
fi

Last edited by Earnestly (2014-02-02 23:03:16)

Offline

#237 2014-02-03 09:05:54

sekret
Member
Registered: 2013-07-22
Posts: 283

Re: Dmenu Hacking Thread

AnSnarkista wrote:

It is still not working for me, and I think it is a lxterminal misconfiguration issue...but thanks for all!

Have you tried mine, which I posted yesterday?

Offline

#238 2014-02-04 07:01:46

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Dmenu Hacking Thread

I created a dedicated dmenu-scripts-collection repo on Github to provide updated overview about the scripts that are available and what purpose they serve.

Feel free to contribute with your own script!

Last edited by orschiro (2014-02-04 07:02:13)

Offline

#239 2014-02-12 00:31:50

Yggdrasil
Member
Registered: 2009-07-21
Posts: 37

Re: Dmenu Hacking Thread

I made a small menu search program similar to Unity's HUD which uses dmenu to display the list of menu entries.
https://github.com/tetzank/qmenu_hud

There are still multiple problems. As mentioned in the readme i only tested it with KDE applications. You probably have to use appmenu-gtk from AUR for gtk applications.

It crashes when you try to get a menu from a window without any menubar, konsole which actually has one too. The Appmenu.Registrar dbus service from the kded module crashes, not my application. But maybe i'm still the cause of it.

Any suggestion and advice would be very welcome.

Offline

#240 2014-02-12 15:50:00

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: Dmenu Hacking Thread

Interesting! I don't see any use case for it myself, but this definitely is one of the most interesting dmenu hacks I've seen in a while wink


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#241 2014-02-12 21:13:31

Yggdrasil
Member
Registered: 2009-07-21
Posts: 37

Re: Dmenu Hacking Thread

I'm using it now over a week and i'm not using it that much actually. I mostly know the shortcuts. But it's still nice to get rid of all menubars and only display the entries if you need them. And have them searchable is even better.

I'm still using mostly KDE applications as i used the desktop in the past. Now with a tiling wm i want to hide every unneeded pixel, even more on a laptop. Vertical space is precious.

Offline

#242 2014-02-14 16:51:58

easysid
Member
From: India
Registered: 2013-01-01
Posts: 256

Re: Dmenu Hacking Thread

How can I get bash like completion in dmenu for filenames? The filename completion patch in dmenu-file-completion does not move the cursor to the end of the completion. Any suggestions?

EDIT: Nevermind. Found Interrobang. Does exactly what I require. Thanks to Trilby and WonderWoofy smile

Last edited by easysid (2014-02-16 16:46:14)

Offline

#243 2014-02-19 13:15:10

dieelt
Member
Registered: 2008-10-12
Posts: 18

Re: Dmenu Hacking Thread

I made a small bash-script for searching files in my $HOME (or elsewhere) using dmenu.

Features:
  * For performance, caches the file list and only updates the list if older than a predefined value (defaults to 5 minutes)
  * Exclude files (defaults to dot-files)
  * Select search directories (defaults to $HOME)

Code (https://github.com/isakkarlsson/fmenu):

#!/bin/bash

usage()
{
    cat << EOF
usage: $0 options

Index and search files using dmenu

OPTIONS:
   -h      Show this message
   -o      Store index [default: /tmp/fmenu_index]
   -i      Search folders [default: $HOME]
   -x      Exclude files [default: ".*\/..*" (i.e. dot-files)]
   -d      dmenu parameters [default: -i -l 20]
   -f      force reloading index [default: false]
   -t      time [default: 5min]
   -u      Just update the index
EOF
}

FORCE=false
INDEX="/tmp/fmenu_index"
DMENU="-i -l 20"
TIME="+5"
INPUT=$HOME
EXCLUDE='.*/\..*'
DRY=false
while getopts "ht:fd:o:i:x:u" OPTION
do
     case $OPTION in
         h)
             usage
             exit 1
             ;;
         f)
             FORCE=true
             ;;
         d)
             DMENU=$OPTARG
             ;;
         t)
             TIME=$OPTARG
             ;;
         o)
             INDEX=$OPTARG
             ;;
         i)
             INPUT=$OPTARG
             ;;
         x)
             EXCLUDE=$OPTARG
             ;;
         u)
             FORCE=true
             DRY=true
             ;;
         ?)
             usage
             exit
             ;;
     esac
done

function index_files {
    find "$INPUT" \( ! -regex "$EXCLUDE" \) | sed 's/ /\\ /g' | sort -f > "$INDEX"
}

if [[ ! -a "$INDEX" ]] ||  ( test `find $INDEX -mmin $TIME` ) || ($FORCE)
then
    index_files
fi

if ( ! $DRY )
then
    cat "$INDEX" | `dmenu $DMENU > /tmp/dmenu_find_output.txt` && cat /tmp/dmenu_find_output.txt | xargs xdg-open
fi

Usage example:

./fmenu -i /home/user -t +10

I use the following in my i3-setup:

bindsym $mod+Shift+d exec --no-startup-id $i3_path/fmenu -d "-i -l 20 -fn "Consolas-10"" -t "+10"

My bash-skills are not great, but the script works fairly nice for me. I don't have that many files in my /home so I don't really know how it scales...

EDIT: changed to #! /bin/bash

Last edited by dieelt (2014-02-19 13:36:11)

Offline

#244 2014-02-19 13:20:58

Earnestly
Member
Registered: 2011-08-18
Posts: 805

Re: Dmenu Hacking Thread

That's not #!/bin/sh though, it only works because bash's sh mode is not strict enough.

If you're interested in improving your skill with bash, see:
http://mywiki.wooledge.org/BashPitfalls/
http://mywiki.wooledge.org/BashGuide/
http://wiki.bash-hackers.org/doku.php

(Don't trust any other website for bash except those two unless those tell you a site is valid.  There's a lot of really horrible bash out there on the internet.)

Last edited by Earnestly (2014-02-19 13:24:09)

Offline

#245 2014-02-22 21:03:09

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: Dmenu Hacking Thread

**EDIT** new project page: https://github.com/carnager/clerk


made a nearly full blown mpd client.

Features:

Add/insert/replace album
Add/insert/replace track
Browse Library by Artist > Album (stole that function somewhere) tongue
Add Random album
Add X random tracks
Show current Playlist and select song to play
Add/insert/replae album/track by currently playing artist
Toggle various mpd settings (single, consume, repeat, random, replaygain, volume, outputs)
Lookup artist/album on allmusic.com (using surfraw)
search for lyrics of currently playing song (using surfraw)

Rate albums
Load albums by rating

enable/disable scrobbling
add/remove current artist to scrobbling blacklist

http://git.53280.de/carnager/scripts/tree/mpdMenu

and the needed lastfm thing for the last 2 options: (would love help on cleaning this monster up)

http://git.53280.de/carnager/scripts/tree/lastfm

Last edited by Rasi (2014-11-18 03:48:53)


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#246 2014-02-25 04:36:53

chickenPie4tea
Member
Registered: 2012-08-21
Posts: 309

Re: Dmenu Hacking Thread

graph wrote:

#125 & #126
I just made this. It lists running applications and switches to the tag they're in. It depends on xdotool and dmenu:

#!/bin/bash
# Search through open programs and switch to their tag

# List all applications (and ignore "plugin-container", since it's flash in firefox)
application=$(xlsclients | grep -v "plugin-container" | cut -d" " -f3 | dmenu -i -p "Switch to")

# Switch to application
xdotool search "$application" windowactivate &> /dev/null

EDIT: Seems like some applications are immune to the approach above (so far gimp, truecrypt and libreoffice).
Here's a version that works with libreoffice and virtualbox but NOT gimp/truecrypt.
EDIT2: And here's a version that works with gimp/truecrypt too, thanks to Army.

Thanks graph, and well done - it's working fine for me with DWM


You can like linux without becoming a fanatic!

Offline

#247 2014-02-25 10:02:33

sekret
Member
Registered: 2013-07-22
Posts: 283

Re: Dmenu Hacking Thread

@Rasi, good one! I'll use your code ass a starting point for my own dmenu mpd script (I e.g. don't need lastfm support), so thanks for that!

Offline

#248 2014-02-25 21:21:05

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: Dmenu Hacking Thread

sekret wrote:

@Rasi, good one! I'll use your code ass a starting point for my own dmenu mpd script (I e.g. don't need lastfm support), so thanks for that!

Today I added the ability to rate albums and load albums by ratings.
Ratings are stored in album folder in a file called rating.txt
seemed the most portable way for me.

Last edited by Rasi (2014-02-25 21:21:53)


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#249 2014-02-26 08:51:54

sekret
Member
Registered: 2013-07-22
Posts: 283

Re: Dmenu Hacking Thread

Nice addition! Although I don't need such a feature, since I like everything in my music collection wink

What I'd like to include is sorting by genre -> artist -> album. I don't see how this is possible with mpc. Do you happen to have any idea?

Offline

#250 2014-02-26 09:12:41

ball
Member
From: Germany
Registered: 2011-12-23
Posts: 164

Re: Dmenu Hacking Thread

dieelt wrote:

I made a small bash-script for searching files in my $HOME (or elsewhere) using dmenu.

Features:
  * For performance, caches the file list and only updates the list if older than a predefined value (defaults to 5 minutes)
  * Exclude files (defaults to dot-files)
  * Select search directories (defaults to $HOME)
[...]

Is there a reason why you don't use locate? It is possible to use a custom database for locating files only in $HOME, too! (See locate(1) and updatedb(8).)

Last edited by ball (2014-02-26 09:13:14)

Offline

Board footer

Powered by FluxBB