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.

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

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

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?

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?

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?

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

Re: Dmenu Hacking Thread

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.

#!/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

Re: Dmenu Hacking Thread

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.

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.

Re: Dmenu Hacking Thread

Add/insert/replace albumAdd/insert/replace trackBrowse Library by Artist > Album (stole that function somewhere) Add Random albumAdd X random tracksShow current Playlist and select song to playAdd/insert/replae album/track by currently playing artistToggle 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)

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.