You are not logged in.

#1 2012-08-22 10:19:01

tlvince
Member
Registered: 2010-07-06
Posts: 68
Website

dmenu-tools: a collection of scripts powered by dmenu

dmenu-tools is a collection of scripts powered by dmenu.

Project home
Project source
AUR package

Included scripts at the time of release:

  • dmenu_edit: Use dmenu to open and edit a file from a given list.

  • dmenu_menu: A recursive dmenu menu.

  • dmenu_mpc: Control mpc via dmenu.

  • dmenu_netcfg: Switch netcfg network profiles.

  • dmenu_run_recent: Sort dmenu items by usage. Append ";" to launch the app in terminal.

Contributions/criticism welcome.

Last edited by tlvince (2012-08-22 17:09:18)

Offline

#2 2012-08-22 16:12:53

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: dmenu-tools: a collection of scripts powered by dmenu

% dmenu_run_recent
/usr/bin/dmenu_run_recent: line 14: dmenu-path: command not found

Which package contains dmenu-path?

Also, your package doesn't include dmenu-run, see

% pacman -Ql dmenu-tools-git
dmenu-tools-git /etc/
dmenu-tools-git /etc/dmenu-tools/
dmenu-tools-git /etc/dmenu-tools/dmenu-tools.conf
dmenu-tools-git /usr/
dmenu-tools-git /usr/bin/
dmenu-tools-git /usr/bin/dmenu_edit
dmenu-tools-git /usr/bin/dmenu_menu
dmenu-tools-git /usr/bin/dmenu_mpc
dmenu-tools-git /usr/bin/dmenu_netcfg
dmenu-tools-git /usr/bin/dmenu_run_recent
dmenu-tools-git /usr/share/
dmenu-tools-git /usr/share/doc/
dmenu-tools-git /usr/share/doc/dmenu-tools/
dmenu-tools-git /usr/share/doc/dmenu-tools/dmenu_edit.mkd
dmenu-tools-git /usr/share/doc/dmenu-tools/dmenu_menu.mkd
dmenu-tools-git /usr/share/doc/dmenu-tools/dmenu_mpc.mkd
dmenu-tools-git /usr/share/doc/dmenu-tools/dmenu_netcfg.mkd
dmenu-tools-git /usr/share/doc/dmenu-tools/dmenu_run_recent.mkd
dmenu-tools-git /usr/share/license/
dmenu-tools-git /usr/share/license/dmenu-tools/
dmenu-tools-git /usr/share/license/dmenu-tools/license.txt

Without looking into the code, is one of the scripts able to use /etc/dmenu-tools/dmenu-tools.conf ? Because according to your install script the user needs to have a config file in the home directory. In case /etc/dmenu-tools/dmenu-tools.conf isn't being used, the right place for it would be /usr/share/doc/dmenu-tools/dmenu-tools.conf.

That's it, nice idea for a package. I'll look into my dmenu-umount script, which is quite ugly right now, because it uses perl inside a shell script. But I don't really know how to implement the perl line written in bash. Anyhow, here's how it looks right now.

#!/bin/sh

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

drive=$(mount | perl -ne 'print qq/$_\n/ for /^\/dev\/(?:mapper\/)?[a-z0-9]+ .* \/media\/(.*) type/' | $DMENU -p 'umount:')
if [ "$drive" = '' ]
then
	exit
fi
udevil unmount "/media/$drive"
if [ $? -eq 0 ]
then
	notify-send "$drive umounted"
elif [ $? -eq 1 ]
then
	notify-send "$drive is busy"
else
	notify-send "something's very wrong! ;)"
fi

(or http://codepad.org/WKwobrli )
As a little explanation, this script works for external media (/dev/sdx) mounted in /media and also encrypted external media mounted in /media, but with the device in /dev/mapper

Last edited by Army (2012-08-22 16:14:51)

Offline

#3 2012-08-22 17:28:48

tlvince
Member
Registered: 2010-07-06
Posts: 68
Website

Re: dmenu-tools: a collection of scripts powered by dmenu

Army wrote:

Which package contains dmenu-path?

Also, your package doesn't include dmenu-run, see

dmenu-path was removed since upstream deprecated it in favour of stest(1). See
dmenu_run (as of v4.5; the current version in [community]).

Note, I renamed the dash separators to underscores in all scripts for in keeping
with upstream.

dmenu_run_recent is broken for the time being, until I figure out how to use
stest.

Upstream also uses XDG_CACHE_HOME in dmenu_run, making dmenu-run redundent.

Army wrote:

In case /etc/dmenu-tools/dmenu-tools.conf isn't being used, the right place for
it would be /usr/share/doc/dmenu-tools/dmenu-tools.conf.

Thanks! I'll fix that shortly.

Army wrote:

That's it, nice idea for a package. I'll look into my dmenu-umount script

Useful script! If you could try to mimic the style I've used in the other
scripts and send me a pull request, I'll gladly include it.

Offline

#4 2012-08-22 18:29:09

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: dmenu-tools: a collection of scripts powered by dmenu

tlvince wrote:

dmenu-path was removed since upstream deprecated it in favour of stest

I just wrote this because you listed it in your original post, but I see you fixed it.

tlvince wrote:

dmenu_run_recent is broken for the time being, until I figure out how to use
stest.

I use a similar script, which uses stest and which was posted in the dmenu thread

#!/bin/bash

# Originally based on code by Dieter Plaetinck.
# Pretty much re-written by Mina Nagy (mnzaki)

dmenu_cmd="dmenu $DMENU_OPTIONS"
terminal="urxvt -e"
max_recent=199 # Number of recent commands to track

cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/dmenu-recent"
recent_cache="$cache_dir/recent"
rest_cache="$cache_dir/all"
known_types=" background terminal terminal_hold "

config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/dmenu-recent"
mkdir -p "$cache_dir"
mkdir -p "$config_dir"
touch "$recent_cache"

IFS=:
if stest -dqr -n "$rest_cache" $PATH 2>/dev/null; then
	stest -flx $PATH | sort -u | grep -vf "$recent_cache" > "$rest_cache"
fi

IFS=" "
cmd=$(cat "$recent_cache" "$rest_cache" | $dmenu_cmd -p execute: "$@") || exit

if ! grep -l "$cmd" "$recent_cache" &> /dev/null; then
	grep -vx "$cmd" "$rest_cache" > "$rest_cache.$$"
	mv "$rest_cache.$$" "$rest_cache"
fi

echo "$cmd" > "$recent_cache.$$"
grep -vx "$cmd" "$recent_cache" | head -n "$max_recent" >> "$recent_cache.$$"
mv "$recent_cache.$$"  "$recent_cache"
# Figure out how to run the command based on the command name, disregarding
# arguments, if any.
word0=${cmd%% *}
match="^$word0$"
get_type () {
	while type=$(echo $known_types | xargs -n1 | $dmenu_cmd -p Type:); do
		[[ $known_types =~ " $type " ]] || continue
		echo "$word0" >> "$config_dir/$type"
		break
	done
	echo $type
}
if ! type=$(grep -lx "$match" -R "$config_dir"); then
	type=$(get_type)
else
	type=${type##*/}
	if ! [[ $known_types =~ " $type " ]]; then
		rm "$config_dir/$type"
		type=$(get_type)
	fi
fi
[[ "$type" = "background" ]] && exec $cmd
[[ "$type" = "terminal" ]] && exec $terminal "$cmd"
[[ "$type" = "terminal_hold" ]] && exec $terminal sh -c "$cmd && echo Press Enter to kill me... && read line"

(or http://codepad.org/iDli9HR2 )

tlvince wrote:

Useful script! If you could try to mimic the style I've used in the other
scripts and send me a pull request, I'll gladly include it.

Ok, I'll try my best, but I'm really no good coder, so it might take a while. But it might be a good learning experience. We'll see wink

Offline

#5 2012-08-26 21:24:11

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: dmenu-tools: a collection of scripts powered by dmenu

dmenu-translate
uses google's translator

#!/bin/bash

##########################
# LIST OF LANGUAGES      #
##########################
# af    (Afrikaans)      #
# sq    (Albanian)       #
# ar    (Arabic)         #
# hy    (Armenian)       #
# az    (Azerbaijani)    #
# eu    (Basque)         #
# be    (Belarusian)     #
# bn    (Bengali)        #
# bg    (Bulgarian)      #
# ca    (Catalan)        #
# zh-CN (Chinese)        #
# hr    (Croatian)       #
# cs    (Czech)          #
# da    (Danish)         #
# nl    (Dutch)          #
# en    (English)        #
# eo    (Esperanto)      #
# et    (Estonian)       #
# tl    (Filipino)       #
# fi    (Finnish)        #
# fr    (French)         #
# gl    (Galician)       #
# ka    (Georgian)       #
# de    (German)         #
# el    (Greek)          #
# gu    (Gujarati)       #
# ht    (Haitian-Creole) #
# iw    (Hebrew)         #
# hi    (Hindi)          #
# hu    (Hungarian)      #
# is    (Icelandic)      #
# id    (Indonesian)     #
# ga    (Irish)          #
# it    (Italian)        #
# ja    (Japanese)       #
# kn    (Kannada)        #
# ko    (Korean)         #
# la    (Latin)          #
# lv    (Latvian)        #
# lt    (Lithuanian)     #
# mk    (Macedonian)     #
# ms    (Malay)          #
# mt    (Maltese)        #
# no    (Norwegian)      #
# fa    (Persian)        #
# pl    (Polish)         #
# pt    (Portuguese)     #
# ro    (Romanian)       #
# ru    (Russian)        #
# sr    (Serbian)        #
# sk    (Slovak)         #
# sl    (Slovenian)      #
# es    (Spanish)        #
# sw    (Swahili)        #
# sv    (Swedish)        #
# ta    (Tamil)          #
# te    (Telugu)         #
# th    (Thai)           #
# tr    (Turkish)        #
# uk    (Ukrainian)      #
# ur    (Urdu)           #
# vi    (Vietnamese)     #
# cy    (Welsh)          #
# yi    (Yiddish)        #
##########################

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

# first run
if [ ! -e $XDG_CONFIG_HOME/dmenu-translate ]
then
	languages=$(echo "" | $DMENU -p "please provide your default languages (see the list of languages in the script), separated by space:")
	if [ "$languages" != '' ]
	then
		echo $languages > $XDG_CONFIG_HOME/dmenu-translate
	fi
else
	languages=$(cat $XDG_CONFIG_HOME/dmenu-translate | sed 's/\ /\\n/g')
	if [ "$languages" != '' ]
	then
		from=$(echo -e "$languages" | $DMENU -p "translate from")
		if [ "$from" != '' ]
		then
			to=$(echo -e "$languages" | $DMENU -p "translate to")
			if [ "$to" != '' ]
			then
				text="$(xsel -o | $DMENU -p "text":)"
				if [ "$text" != '' ]
				then
					echo $(wget --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1" "http://translate.google.com/translate_a/t?client=x&text=$text&hl=$from&sl=$from&tl=$to" -qO-)| awk -F\" '{ print $6 }' | tr \\n \\0 | $DMENU -p "translation from $from to $to:" | xsel -i
				fi
			fi
		fi
	fi
fi

or http://codepad.org/Cggq1GiG

For code improvements (I'm not sure if my way is the best way), please tell me, I'm willing to learn!

edited: little bug in the script
edited again: I'll try to translate it to your style and reupload it, if you like what this script does and want to include it to your collection

Last edited by Army (2012-08-27 10:30:34)

Offline

Board footer

Powered by FluxBB