You are not logged in.

#326 2018-11-08 17:12:47

From: Netherlands
Registered: 2012-06-20
Posts: 884

Re: Dmenu Hacking Thread

Unstack wrote:

dmenu hack for querying Google. [GIF Preview (>1mb)]

Tell me what you think.

Hey Unstack, I like your tool, especially the 'back & cancel' button.
I'm a nitwit in python but I'm going to try to use that part for other dmenu script, like osx-finder or git-jumper.

As for what your tool actually does, I miss the address together with the search, so you get something like: search enter back enter back enter back etc...
If the URL was visible in the search it would be a winner , for me;)

A little tool I made, alarm based on 'sleep':

set -xe
if [ -f "$XDG_CONFIG_HOME"/dmenu/dmenurc ]; then
  . "$XDG_CONFIG_HOME"/dmenu/dmenurc

alarm_clock() {
  reason=$(echo '' | $demcmd -p "ReasonForAlarm?" -w '375')
  if [ -z "$reason" ]; then  reason=Alarm; fi
  timer=$(echo '' | $demcmd -p "TimeToAlarm:" -w '375')
  (sleep "$timer" | $dmalarm -p "$reason" -w '540' -x '675' -y '500')

exit 0

+ teh config lines:

demcmd='dmenu -i -fn Monospace-14:normal -nb #222222 -nf #ff7f50 -sb #222222 -sf #f5deb3'
dmalarm='dmenu -fn Monospace-40:normal -sb #222222 -sf #dd0000'

edit: add e to dmcmd, which is also in my list...
edit2: dmenu can run multiple instances of the same script
I added  a reason for alarm(default=Alarm), like movie start or taxi, etc
Right now it shows 16 characters increase last width to change that.

Last edited by qinohe (2018-11-20 16:11:30)


#327 2018-11-13 11:59:46

Registered: 2017-04-21
Posts: 5

Re: Dmenu Hacking Thread

I often open a new terminal window and want to quickly jump to the working directory that I have in another window. Here is a fragment of my .bashrc for doing that:

choose_from_cwds() {
	for PROCID in $(pgrep '^bash$'); do
		readlink -e /proc/$PROCID/cwd
	done \
	| sort -u \
	| dmenu -l 5
alias chd='cd $(choose_from_cwds)'


#328 2018-11-16 16:13:46

Registered: 2017-04-21
Posts: 5

Re: Dmenu Hacking Thread

Here's another one for browsing git commits and selecting their hash values. I use it for example to select points for a diff.

choose_git_commit() {
    git log --date='format:%Y-%m-%d %H:%M' \
        | paste -sd'\t' \
        | sed 's/commit /\n/g; s/\(Author\|Date\)://g; s/<[^>]*>//g;
               s/ \+/ /g; s/\t\+/  /g' \
        | cut -c -150 \
        | dmenu -i -l 10 \
        | cut -d' ' -f 1
alias Gdd='git diff $(choose_git_commit) $(choose_git_commit)'

There is one problem with this script: it is very slow on my elderly laptop (ThinkPad X200). However, on a newer desktop PC, it works smoothly. Apparently, dmenu is not very well suited for long strings. Does anyone know how to improve it?

Solved the performance issue. The problem was not long strings, but tab characters. I changed the script accordingly, now it runs smoothly.

Last edited by msum (2018-11-16 16:23:11)


#329 2019-01-14 18:58:58

Registered: 2019-01-14
Posts: 1

Re: Dmenu Hacking Thread

My script opens a file somewhere in your home directory by typing part of its name, rather than finding it in a file manager.  It's intended to be assigned to a keyboard combination, so you might press something like Win-Space, then start typing part of a filename, then press Enter.


#This script lets a user select a file to open by typing part of its
#name, kind of like Quicksilver (only lighter-weight).  It's meant to
#be invoked by a shortcut key such as Windows-space.
#Depends on:
# dmenu
# locate / updatedb
# xdg-open

#Set this variable to the directory you want to open files in

make_files_db() {
    #Create the database
    #Unforunately there seems to be no good way to use updatedb to create just a single database with files from
    #multiple different directories.
    #There are 2 versions of updatedb, and GNU locate has an extra option --localpaths which lets you specify
    #multiple paths with one command.  mlocate, the version I'm using, doesn't.
    #However, mlocate is apparently newer, and has the improvement that it reuses the old database
    #to save time, and apparently if you install both then they'll both build their databases in the background.
    updatedb -l 0 -U "$DIRECTORY_TO_INCLUDE" -o "$TEMP_DB" --prune-bind-mounts no

    #Save only the filenames, not the full path, in the temporary file (see below for why).
    #Skip hidden files.
    #The "while read line" trick is like a for loop, but iterates over lines instead of space-delimited
    #items.  I found the trick here:
    locate "$DIRECTORY_TO_INCLUDE" -d "$TEMP_DB" | grep -v "/\." | while read line ; do basename "$line" ; done  > "$TEMP_FILE"

if [ "$1" == "-r" ]
    #User selected to rebuild the temporary file
    echo "Temporary file rebuilt"
    exit 0
elif [ ! -f "$TEMP_FILE" ]
    echo "Building temporary file... (Use $0 -r to rebuild it - it's recommended to set this to happen regularly, e.g. daily or when your computer starts)"

#Select a file to edit.
#The selection menu only displays the file's name here, not
#the full path.
#The reason for that is that otherwise there would be too many choices matching the letters you type -
#if the letters match a directory name, then all the files in that directory would also be included in the choices.
chosen_file=`cat "$TEMP_FILE" | dmenu -i`

open_file() {
    #For many programs there's a benefit to setting the current directory to the directory of the file
    cd `dirname $1`

    #Open the file according to how they configured that type of file in their desktop environment
    xdg-open "$1"

if [ -n "$chosen_file" ]  #If a file was selected
	#Prepend a / to increase the chances of matching only one file.
    #The first grep is for directories, and ensures that only the directory itself is matched and not things in the directory.
    #The second grep excludes hidden files.
    locate -d "$TEMP_DB" /$chosen_file | grep "$chosen_file$" | grep -v "/\." > "$TEMP_RESULT"

	#Count how many files have the filename that was selected.
	lines=`cat "$TEMP_RESULT" | wc -l`

	if [ "1" = "$lines" ]
		#If there's exactly one file of that name, edit it.

		#Get the full path of the file
		full_file=`cat "$TEMP_RESULT"`
		open_file "$full_file"
	elif [ "0" = "$lines" ]
		echo "Not found"
		#There were multiple files that share the same filename.
		#Ask the user which file they want to edit by displaying the full path
		#this time.
		full_file=`cat "$TEMP_RESULT" | dmenu -i -p "Which $chosen_file?"`

		if [ -n "$full_file" ]
			open_file "$full_file"


#330 2019-06-17 13:44:16

Registered: 2017-10-13
Posts: 5

Re: Dmenu Hacking Thread

This is
It opens manpages in llpp after a conversion. It's a bit nicer to read than in the terminal in a monospaced font.


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

PAGE=$( apropos -s 1 . | awk '{print $1}' | $DMENU )
file=$(mktemp /tmp/beautiful_man.XXXXXXXXX)
man -t "$PAGE" > $file
llppac -t ps $file

Works nice with this in the llpp.conf



Board footer

Powered by FluxBB