Users browsing this thread: 1 Guest(s)
prx*
Members
Hi,
very nice idea. Indeed, dmenu is extremely useful.
Here are a few scripts I use almost daily. Some are quite old, and kinda ugly when I read them now.


## Appearance
First, make sure they all share the same look :

Code:
$ cat $HOME/.dmenurc
l=15
fn="FiraCode-11"
# gruvbox
nb="#282828"
nf="#a89984"
sf="#282828"
sb="#458588"

## daddbmk/dloadbmk
Browser independent bookmarking:

Code:
#!/bin/sh
# daddbmk
# store an URL in $HOME/.bookmarks

# edit the page
bmk=$HOME/.bookmarks

# choose downloader
#D="wget -O-" # mosts linux
#D="curl -L" # with curl
D="ftp -o-"   # OpenBSD

# dmenu
test -s $HOME/.dmenurc && . $HOME/.dmenurc
PROMPT="url:"

URL=$(xclip -o | dmenu -sb ${sb} -sf ${sf} -nb ${nb} -nf ${nf} -fn ${fn} -p "$PROMPT")
test -z "${URL}" && exit
TITLE="$(${D} "${URL}" | grep '<title>' | \
    head -n1 | \
    sed -e 's;<title>;;' -e's;</title>;;' |\
    awk '{$1=$1};1'
)"
echo "${TITLE} ${URL}" >> "${bmk}"
sort -u "${bmk}" -o "${bmk}"

# edit bookmark
st -e $EDITOR "${bmk}"

## search engine
Code:
#!/bin/sh
#search engines with dmenu
# If any text is selected, it is directly pasted at input

#dmenu colors
test -s $HOME/.dmenurc && . $HOME/.dmenurc
# prompt
P="engine <search>:"

#DEFAULT='https://html.duckduckgo.com/html/?kh=1&q='
DEFAULT='https://duckduckgo.com/?kh=1&q='
#DEFAULT='https://www.mojeek.com/search?q='

INPUT=$(echo "duckduckgo
qwant
openstreetmap
manobsd
obsdmisc
obsdports
wiki
wikien
dic
synonyme
en2fr
fr2en
pirate
sound
image" |dmenu -i -fn $fn -nb $nb -nf $nf -sb $sb -sf $sf -p "$P")
ENGINE=$(echo $INPUT |cut -d ' ' -f 1 )
SEARCH=$(echo $INPUT |cut -d ' ' -f2- |sed 's/ /+/g')
if [ -n "$SEARCH" ]; then
   case $ENGINE in
      d | duckduckgo) RES="https://duckduckgo.com/?kh=1&kl=fr-fr&ks=m&kj=kt&ky=-1&kad=fr_FR&q=$SEARCH";;
      qwant) RES="https://www.qwant.com/?q=$SEARCH&t=all" ;;
      osm | openstreetmap ) RES="https://www.openstreetmap.org/search?query=$SEARCH"
      ;;
      obsdmisc ) RES="https://marc.info/?l=openbsd-misc&w=2&r=1&q=b&s=$SEARCH" ;;
      obsdports ) RES="https://marc.info/?l=openbsd-ports&w=2&r=1&q=b&s=$SEARCH" ;;
      manobsd ) RES="https://man.openbsd.org/$SEARCH" ;;
      wiki)  RES="http://fr.wikipedia.org/w/index.php?title=Spécial%3ARecherche&search=$SEARCH&go=Lire" ;;
      i | image ) RES="https://duckduckgo.com/?ia=images&iax=images&q=$SEARCH" ;;
      wikien | ew )  RES="http://en.wikipedia.org/w/index.php?title=Spécial%3ARecherche&search=$SEARCH&go=Lire" ;;
      dic )  RES="http://www.le-dictionnaire.com/definition.php?mot=$SEARCH" ;;
      syn | synonyme ) RES="http://www.synonymes.com/synonyme.php?mot=$SEARCH&x=0&y=0";;
      en2fr ) RES="http://www.wordreference.com/enfr/$SEARCH";;
      fr2en ) RES="http://www.wordreference.com/fren/$SEARCH";;
      pirate ) RES="https://pirateproxy.name/search.php?q=$SEARCH";;
      sound ) RES="https://soundcloud.com/search?q=$SEARCH";;
      # Le suivant eterm le choix par défaut
      * )
        SEARCH=$(echo $INPUT |cut -d ' ' -f1- |sed 's/ /+/g')
          RES="$DEFAULT$SEARCH" ;;
   esac
fi

if [ "$RES" != "" ]; then
    "$BROWSER" $RES
fi
exit
Code:
#!/bin/sh
test -s $HOME/.dmenurc && . $HOME/.dmenurc

url="$(dmenu -nb $nb -nf $nf -sb $sb -sf $sf -fn $fn -i -l $l < $HOME/.bookmarks | \
    awk '{print $NF}')"
    
if [ -n "$url" ]; then
    $BROWSER "$url"
fi
exit 0

## music player daemon
Code:
#!/bin/sh
#Gestion de mpd avec dmenu et mpc

test -s $HOME/.dmenurc && . $HOME/.dmenurc

OPTION="-sb ${sb} -sf ${sf} -nb ${nb} -nf ${nf} -fn ${fn} -l $l -i"

index=`mpc playlist |nl -s ' ' |dmenu $OPTION -p "Que jouer?" |awk '{print $1}'`
if [ "$index" != "" ]; then
    mpc -q play $index
fi
exit 0;

## ssh quick start
Code:
#!/bin/sh
# run ssh session in one hosts listed in
#   $HOME/.ssh/config
#   $HOME/.ssh/known_hosts
# Require : x11/dmenu <https://tools.suckless.org/dmenu/>
# Author : prx <prx@si3t.ch>
# Licence : MIT

# term ?
TERMINAL='st'

# few options for dmenu
test -s $HOME/.dmenurc && . $HOME/.dmenurc
PROMPT="ssh host:"

C=$HOME/.ssh/config
K=$HOME/.ssh/known_hosts

HOST=$(
(awk '/Hoterm [^*]/ {print $2}' "${C}"
cut -d' ' -f 1 "${K}" |\
    cut -d',' -f1 |\
    sed -e 's;\[;;' -e 's;\];;'
) | sort -u \
| dmenu -l ${l} \
-fn "${fn}" \
-nb "${nb}" \
-nf "${nf}" \
-sb "${sb}" \
-sf "${sf}" \
-p "${PROMPT}")

if [ -n "${HOST}" ]; then
    case "${HOST}" in
        *:*) "${TERMINAL}" -e "ssh ssh://${HOST}" ;;
        *) "${TERMINAL}" -e "ssh ${HOST}" ;;
    esac
fi

exit

## manpage finder
Written at first by eol. A little modified. This one is sick.
Code:
#!/bin/sh

set -e

# TODO or not ?
# Some man page are different on different architecture
# For a simpler interface, this is not handled as only
# the last component of path is displayed in dmenu

sp="$HOME/man /usr/share/man/ /usr/local/man/ /usr/X11R6/man/"
mandb=~/.man.db
readonly sp mandb

usage() {
print -u2 "${0##*/}:
    pipe locate output from ~/.man.db as prepopulated by mk_man_db
    into dmenu. User can select one or more man page thanks to
    dmenu multiselection. Read dmenu(1) for more information ;)

    You can customize the window using the \"man\" class in ~/.Xresources
    with line such as:
        man*scrollBar: false
        man*reverseVideo: true

    -b build only mode. ~/.man.db is created or updated.
    -h Print this message."
}

mk_man_db() {
    /usr/libexec/locate.updatedb \
        --fcodes="$mandb" \
        --searchpaths="$sp"
    
}

while getopts "bh" opt; do
    case $opt in
        b)    mk_man_db
            exit 0;;
        h|*)    usage
            exit 1;;
        
    esac
done

do_need_update() {
    [[ ! -s $mandb ]] || {
        local lastdbmod lastmanpathdirsmod
        lastdbmod=$(stat -f "%m" $mandb)
        lastmanpathdirsmod=$(stat -f "%m" $sp |sort -r |sed q)
        [[ $lastdbmod < $lastmanpathdirsmod ]]
    } && mk_man_db
}

manpage_choose() {
    test -s $HOME/.dmenurc && . $HOME/.dmenurc
    locate -b -d "${mandb}" . |sed 's,.*/,,;/mandoc.db/d' \
    | dmenu -l ${l} \
    -fn "${fn}" \
    -nb "${nb}" \
    -nf "${nf}" \
    -sb "${sb}" \
    -sf "${sf}" \
    -p "Man page : " |uniq


}

manpage_show() {
IFS='
'
    local manpage=$(manpage_choose)
    [ "$manpage" ] && {
        for m in $manpage
        do
            name=${m%.([0-9]|3p)}
            section=${m##*.}
            f=$(locate -d "${mandb}" /$m |sed q)
            [ -f "$f" ] && \
                case $section {
                    0)
                        xterm -class man -T "man | $name($section)" \
                            -e less -eR "$f" &
                        ;;
                    [1-9]|3p)
                        xterm -class man -T "man | $name($section)" \
                            -e man -l "$f" &
                        ;;
                    *)
                        ;;
                }
        done
    }
}

    do_need_update
    manpage_show &

exit $?

## file search
Code:
#!/bin/sh
# search for file in $sp
test -s $HOME/.dmenurc && . $HOME/.dmenurc
#sp="$HOME /etc /bin /usr/local"
sp="$HOME"

cachedir="${XDG_CACHE_HOME:-"$HOME/.cache"}"
cache="$cachedir/dlocate.db"

mk_cache()
{
    /usr/libexec/locate.updatedb \
    --fcodes="$cache" \
    --searchpaths="$sp"
}

if [ -s $cache ]; then
    lastdbmod=$(stat -f "%m" $cache)
    lastspmod=$(stat -f "%m" $sp |sort -r |sed q)
    test $lastdbmod -lt $lastspmod && mk_cache
else
    mk_cache
fi

prompt="locate:"

res=$(locate -b -d "${cache}" . | dmenu \
        -l ${l} \
        -i \
        -fn "${fn}" \
        -nb "${nb}" \
        -nf "${nf}" \
        -sb "${sb}" \
        -sf "${sf}" \
        -p "${prompt}" \
)
notify-send "${res}"
test -f "${res}" && xdg-open "${res}"

## waybackmachine
Code:
#!/bin/sh
test -s $HOME/.dmenurc && . $HOME/.dmenurc
PROMPT="waybackmachine:"

url="$(xclip -o | dmenu -sb ${sb} -sf ${sf} -nb ${nb} -nf ${nf} -fn ${fn} -p "$PROMPT")"
test -z "${url}" && exit

$BROWSER "https://web.archive.org/save/$url"
$BROWSER "https://archive.is/?url=$url"

I also use wall setter, scrot'n'upload, note manager, but far less good as the previous mentioned.

edit : a few more explanation here (in french, sorry) : gemini://si3t.ch/Logiciel-libre/Suckless/dmenu.gmi


Messages In This Thread
Dmenu Scripts - by pfr - 09-06-2021, 03:38 AM
RE: Dmenu Scripts - by seninha - 09-06-2021, 09:35 AM
RE: Dmenu Scripts - by prx* - 09-06-2021, 09:42 AM
RE: Dmenu Scripts - by pfr - 09-06-2021, 10:48 AM
RE: Dmenu Scripts - by prx* - 10-06-2021, 04:28 AM
RE: Dmenu Scripts - by Gorm - 11-06-2021, 09:17 PM