You are not logged in.

#1 2008-06-08 10:09:29

nucleuswizard
Member
From: Serbia
Registered: 2007-10-07
Posts: 79

Dmenu help!!!

Is there any link to dmenu examples or dmenu scripts.I recently installed awsome and dmenu but I don't know how to configure dmenu...

Offline

#2 2008-06-08 10:34:18

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Dmenu help!!!

I don't have a script available, but this would be a very basic example:

#!/bin/bash
`dmenu < menu.txt`

Dmenu takes a newline-separated list of values on standard input, it then returns on standard output the selected choice. I think I have a post about it on my blog somewhere.

Offline

#3 2008-06-08 10:54:03

nucleuswizard
Member
From: Serbia
Registered: 2007-10-07
Posts: 79

Re: Dmenu help!!!

Thanks I founded on your blog wink wink

Offline

#4 2008-06-08 11:08:30

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Dmenu help!!!

I have a nice menu script:
You need to touch ~/.dddmenu, or, if you want, give it a few starting entries too. Then you run it and if you give it a new (unique) command it will add it to .dddmenu
(made for dash, in bash I'm not sure if [ needs to be [[)

#!/bin/dash
newentry=$(dmenu < ~/.dddmenu)
[ -z $newentry ] && exit
[ -z $( (cat ~/.dddmenu; echo $newentry) | sort | uniq -d) ] && echo $newentry >> ~/.dddmenu

exec setsid $newentry

Here is a script for cmus:
Needs the latest git that can do remote searching. You run the script, type in a search command, and it will find the first one and play from there. Goes to view sorted (fix if you want, you can use 1..4)
made for bash (see the difference)

#!/bin/bash
song=$(dmenu < ~/.cmus/search-history)
[[ -n ${song} ]] && echo -e "view sorted\n/${song}\nwin-activate" | cmus-remote

Offline

#5 2008-06-08 15:03:36

robmaloy
Member
From: Germany
Registered: 2008-05-14
Posts: 263

Re: Dmenu help!!!

if you want submenus, tell me. wrote a little script for that


☃ Snowman ☃

Offline

#6 2008-09-29 18:08:12

abijr
Member
Registered: 2008-05-18
Posts: 71

Re: Dmenu help!!!

talking of dmenu....
Do you know where are the bookmarks of firefox (location)
so you can launch them directly using dmenu?

Offline

#7 2008-09-29 18:17:09

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Dmenu help!!!

abijr wrote:

talking of dmenu....
Do you know where are the bookmarks of firefox (location)
so you can launch them directly using dmenu?

~/<USER_NAME>/.mozilla/firefox/<UGLY_FILE_NAME>.default/bookmarks.html

Offline

#8 2008-09-29 18:25:46

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Dmenu help!!!

That's not right, bookmarks are now in a SQL file, places.sqlite. So any bookmarks script is impossible.

Offline

#9 2008-09-29 18:30:38

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Dmenu help!!!

Procyon wrote:

That's not right, bookmarks are now in a SQL file, places.sqlite. So any bookmarks script is impossible.

Holy crapola! I didn't know that it changed. Thanks Procyon.

Offline

#10 2008-09-29 22:28:29

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: Dmenu help!!!

For the original question:
RTFW aka Read The Fine Wiki. You will be amazed by all the info you can find on it, so it's a good idea to search first and ask later.

Last edited by Mr.Elendig (2008-09-29 22:29:48)


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#11 2008-10-10 01:55:49

abijr
Member
Registered: 2008-05-18
Posts: 71

Re: Dmenu help!!!

Hey I think that in the about:config of firefox you can tell firefox to "export
your bookmarks every now and than.

Offline

#12 2009-04-22 07:02:19

robmaloy
Member
From: Germany
Registered: 2008-05-14
Posts: 263

Re: Dmenu help!!!

Procyon wrote:

That's not right, bookmarks are now in a SQL file, places.sqlite. So any bookmarks script is impossible.

actually not. you can query and alter sqlite files i.e. using python or with the sqlite3 command (package sqlite3)

cd ~/.mozilla/firefox/YOURPROFILEDIRNAME
cp places.sqlite tmp.sqlite # mozilla locks the DB
sqlite3 tmp.sqlite "SELECT moz_bookmarks.title AS title, moz_places.url AS url
FROM moz_bookmarks INNER JOIN moz_places
ON moz_bookmarks.fk = moz_places.id;"

which will give you a list of
TITLE|URL

(including RSS feeds)

Last edited by robmaloy (2009-04-22 07:32:58)


☃ Snowman ☃

Offline

#13 2009-04-22 09:03:21

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Dmenu help!!!

That is pretty cool, can you also do it so the directory structure is preserved?

Offline

#14 2009-04-22 10:19:13

b3n
Member
Registered: 2008-11-12
Posts: 20

Re: Dmenu help!!!

#!/bin/sh

TERMI="urxvt -e sh -c"
CACHE="$HOME/.dmenu_cache_recent"

MOST_USED=`sort $CACHE | uniq -c | sort -rn | colrm 1 8`
RUN=`(echo "$MOST_USED"; dmenu_path | grep -vxF "$MOST_USED") | dmenu "$@"` &&
(echo $RUN; head -n 99 $CACHE) > $CACHE.$$ && mv $CACHE.$$ $CACHE
case $RUN in
    *\;) exec $TERMI "$RUN";;
    *) exec $RUN;;
esac

Offline

#15 2009-04-24 07:20:14

robmaloy
Member
From: Germany
Registered: 2008-05-14
Posts: 263

Re: Dmenu help!!!

Procyon wrote:

That is pretty cool, can you also do it so the directory structure is preserved?

that should be possible.
i will do some further investigation

edit:

python script to display firefox bookmarks
recursive functions ftw

#!/usr/bin/python
import os
import pysqlite2.dbapi2 as sqlite
import shutil
import ConfigParser
import random

# change this if you want:
DISPLAY_PROFILE_NUMBER = 0

parser = ConfigParser.ConfigParser()

homedir = os.path.expanduser('~')
moz = '.mozilla/firefox'
moz_dir = os.path.join(homedir, moz)
tmpdir = '/tmp'

BOOKMARK = 1
FOLDER = 2


query_folders = 'SELECT id, title FROM moz_bookmarks WHERE type = 2;'
query_bookmarks = 'SELECT moz_bookmarks.id, moz_bookmarks.parent, moz_bookmarks.title, moz_places.url \
                    FROM moz_bookmarks \
                    INNER JOIN moz_places \
                    ON moz_bookmarks.fk = moz_places.id \
                    WHERE moz_bookmarks.type = 1;'

def getprofiles():
    profilesini = os.path.join(moz_dir, 'profiles.ini')
    parser.read(profilesini)

    prof = []
    i = 0
    while parser.has_section('Profile' + str(i)):
        name = parser.get('Profile' + str(i), 'Name')
        path = parser.get('Profile' + str(i), 'Path')
        prof.append({'name': name, 'path': path})
        i += 1
    return prof

def randfilename():
    tmp = 'moz_bmarx_'
    for i in range(12):
        tmp += chr(random.randint(97, 122))
    return tmp

def opendb(profile):
    places = os.path.join(moz_dir, profile['path'], 'places.sqlite')
    tmpfile = os.path.join(tmpdir, randfilename())
    shutil.copy(places, tmpfile)

    db = sqlite.connect(tmpfile)
    return db

def printitem(indent, title, url=''):
    '''
    strng = indent * '.'
    if indent > 0:
        strng += '|-- '
        '''
    strng = indent * '\t'

    strng += title + ':'
    print(strng.encode('utf-8'))
    
    if (url):
        urlstrng = (indent + 1) * '\t' + url
        print(urlstrng.encode('utf-8'))


def printtree(db, parent, indent):
    cur = db.cursor()
    query = 'SELECT id, type FROM moz_bookmarks WHERE parent = ' + str(parent)
    cur.execute(query)
    res = cur.fetchall()

    for item in res:
        if item[1] == FOLDER:
            query_name = 'SELECT title FROM moz_bookmarks WHERE id = ' + str(item[0])
            cur.execute(query_name)
            name, = cur.fetchone()
            
            printitem(indent, name)
            printtree(db, item[0], indent + 1)


        if item[1] == BOOKMARK:
            query_bmark = 'SELECT moz_bookmarks.title, moz_places.url \
                    FROM moz_bookmarks \
                    INNER JOIN moz_places \
                    ON moz_bookmarks.fk = moz_places.id \
                    WHERE moz_bookmarks.id = ' + str(item[0])
            cur.execute(query_bmark)
            title, url = cur.fetchone()

            printitem(indent, title, url)

profs = getprofiles()

prf = profs[DISPLAY_PROFILE_NUMBER]
db = opendb(prf)
print 'Bookmarks from Profile ' + prf['name']

printtree(db, 1, 0)

Last edited by robmaloy (2009-04-24 09:24:56)


☃ Snowman ☃

Offline

#16 2009-05-03 19:49:02

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Dmenu help!!!

@robmaloy: Thanks! I just saw it now.

I have one more request, that is getting all the history, with both URL and title. If it's possible sorted by the last access time.

Offline

#17 2009-05-06 18:02:54

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Dmenu help!!!

I think I got it, I changed your script a bit so it prints all information on one line in 3 columns (directory / title / url). That way you can use dmenu to search for an entry and have firefox launch the URL.

Launcher:

#! /bin/dash
url=$(bookmarkhistory_fx_export | dmenu -i -l 7 -rs -ni -xs | cut -sf3)
[ -z "$url" ] && exit
firefox "$url"

bookmarkhistory_fx_export:

#!/usr/bin/python
import os
import pysqlite2.dbapi2 as sqlite
import shutil
import ConfigParser
import random
import time

# change this if you want:
DISPLAY_PROFILE_NUMBER = 0

parser = ConfigParser.ConfigParser()

homedir = os.path.expanduser('~')
moz = '.mozilla/firefox'
moz_dir = os.path.join(homedir, moz)
tmpdir = '/tmp'

BOOKMARK = 1
FOLDER = 2


query_folders = 'SELECT id, title FROM moz_bookmarks WHERE type = 2;'
query_bookmarks = 'SELECT moz_bookmarks.id, moz_bookmarks.parent, moz_bookmarks.title, moz_places.url \
                    FROM moz_bookmarks \
                    INNER JOIN moz_places \
                    ON moz_bookmarks.fk = moz_places.id \
                    WHERE moz_bookmarks.type = 1;'

def getprofiles():
    profilesini = os.path.join(moz_dir, 'profiles.ini')
    parser.read(profilesini)

    prof = []
    i = 0
    while parser.has_section('Profile' + str(i)):
        name = parser.get('Profile' + str(i), 'Name')
        path = parser.get('Profile' + str(i), 'Path')
        prof.append({'name': name, 'path': path})
        i += 1
    return prof

def randfilename():
    tmp = 'moz_bmarx_'
    for i in range(12):
        tmp += chr(random.randint(97, 122))
    return tmp

def opendb(profile):
    places = os.path.join(moz_dir, profile['path'], 'places.sqlite')
    tmpfile = os.path.join(tmpdir, randfilename())
    shutil.copy(places, tmpfile)

    db = sqlite.connect(tmpfile)
    return db

def printitem(folder, title, url=''):
     if not title: title="noname"
     if not folder: folder="nofolder"
     if not url: url="nourl"
     print folder.encode("UTF-8")+"\t"+title.encode("UTF-8")+"\t"+url.encode("UTF-8")


def printtree(db, parent, recentfolder):
    cur = db.cursor()
    query = 'SELECT id, type FROM moz_bookmarks WHERE parent = ' + str(parent)
    cur.execute(query)
    res = cur.fetchall()

    for item in res:
        if item[1] == FOLDER:
            query_name = 'SELECT title FROM moz_bookmarks WHERE id = ' + str(item[0])
            cur.execute(query_name)
            name, = cur.fetchone()
            
            printtree(db, item[0], recentfolder+"/"+name)

        if item[1] == BOOKMARK:
            query_bmark = 'SELECT moz_bookmarks.title, moz_places.url \
                    FROM moz_bookmarks \
                    INNER JOIN moz_places \
                    ON moz_bookmarks.fk = moz_places.id \
                    WHERE moz_bookmarks.id = ' + str(item[0])
            cur.execute(query_bmark)
            title, url = cur.fetchone()
            if url[0:5]=="place": continue
            printitem(recentfolder, title, url)

def allhistory(db):
    cur=db.cursor()
    query_history = 'SELECT moz_historyvisits.visit_date, moz_places.title, moz_places.url FROM moz_historyvisits INNER JOIN moz_places ON moz_historyvisits.place_id = moz_places.id ORDER BY moz_historyvisits.visit_date DESC;'
    cur.execute(query_history)
    res = cur.fetchall()
    for item in res:
        printitem(time.ctime(item[0]/1000000),item[1],item[2])

profs = getprofiles()

prf = profs[DISPLAY_PROFILE_NUMBER]
db = opendb(prf)
print 'Bookmarks from Profile ' + prf['name']

printtree(db, 1, "")

allhistory(db)

Offline

Board footer

Powered by FluxBB