You are not logged in.

#351 2020-01-30 04:39:32

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,171

Re: Dmenu Hacking Thread

Did some changes

#!/bin/bash

shopt -s lastpipe
url_vid="https://invidio.us"
channels=$HOME/.channels  
#sel=$(echo "$channels" | sed 's/\ [^ ]*$//' | dmenu -l 20)

dmenu -l 20 -p "YouTube Channels" < $channels | read -a "sel"

[[ ! $sel ]] && exit

list=$(curl -s "${sel[@]:1}" | sed -n 's/.*<p><a href="\(\/watch?v=[^"]*\)">\([^<]*\).*/\1;\2/p')
sel2=$(echo "$list" | sed 's/.*;//'| dmenu -l 20)

[[ ! $sel2 ]] && exit

mpv ${url_vid}$(echo "$list" | sed -n "s/;$sel2$//p")

I used channels list separated by space (instead of ";" ) in separate file, and added exit so when no channels of video is selected script stops instead of going to next step.
The output of curl was too much for my scripting capabilities so I left it as it is.

Last edited by Docbroke (2020-01-30 04:40:44)


Arch is home!
sway rofi qutebrowser vifm vim mutt lizzy pass

Offline

#352 2020-01-30 05:55:21

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 28,501
Website

Re: Dmenu Hacking Thread

qinohe wrote:
chans=$(printf "%s\n" "${options[@]%%;*}" | dmenu -i)

Yes, but the line in the dmenu menu is one line.

Can not reproduce, even with -l.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#353 2020-01-30 06:39:49

zf
Member
Registered: 2019-03-04
Posts: 3

Re: Dmenu Hacking Thread

I'm trying to bind C-v to the functionality of C-Y to mimic how traditional pasting works when copying a cell content (C-c) from LibreOffice Calc and pasting to an application like Firefox. Seems simple enough, especially when C-v and C-V looks like it's unbounded, but the following does not work as I would expect. I simply copied the code for XK_Y to XK_v and XK-V, but end result is that the functionality of C-y and C-Y is duplicated in C-v and C-V, respectively. To re-iterate, I want the functionality of C-Y to be C-v, not C-V. Any help is much appreciated.

--- dmenu-4.9/dmenu.c   2020-01-29 23:35:55.978968100 -0500
+++ dmenu-4.9/dmenu.c   2020-01-30 00:41:13.247510200 -0500
@@ -354,6 +354,14 @@
            while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
            insert(NULL, nextrune(-1) - cursor);
        break;
+       case XK_v:
+           XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
+                             utf8, utf8, win, CurrentTime);
+           return;
+       case XK_V:
+           XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
+                             utf8, utf8, win, CurrentTime);
+           return;
    case XK_y: /* paste selection */
    case XK_Y:
        XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,

Offline

#354 2020-01-30 14:19:39

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

jasonwryan wrote:
qinohe wrote:
chans=$(printf "%s\n" "${options[@]%%;*}" | dmenu -i)

Yes, but the line in the dmenu menu is one line.

Can not reproduce, even with -l.

So you say all lines in your dmenu menu are produced under each other and not besides(separated by space) ?

Are you using some patched version and can anyone else confirm this is also working for them?

Offline

#355 2020-01-30 14:45:11

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

Docbroke wrote:

...
and added exit so when no channels of video is selected script stops instead of going to next step.
...

I have never seen this as a real problem and just escape, non of my layered dmenu scripts have an 'exit'

Nevertheless, nice  script. This one script has seen a lot of forms already. Good to see dmenu is very much alive;)
I was sticking to dmenu but I thought everyone has stepped over to rofi ...

Offline

#356 2020-01-30 16:36:24

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 28,501
Website

Re: Dmenu Hacking Thread

qinohe wrote:
jasonwryan wrote:
qinohe wrote:
chans=$(printf "%s\n" "${options[@]%%;*}" | dmenu -i)

Yes, but the line in the dmenu menu is one line.

Can not reproduce, even with -l.

So you say all lines in your dmenu menu are produced under each other and not besides(separated by space) ?

Are you using some patched version and can anyone else confirm this is also working for them?

Yes. It's not patched, it is the expected behaviour. You can see that for yourself, each item of the array is split onto a new line:

printf "%s\n" "${options[@]%%;*}"

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#357 2020-01-30 16:45:29

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

Yes, sure I do see that 'printf "%s\n"'
However I'm looking for a way to get this output

NBA
BBALLBREAKDOWN
Basketball Box

not this

NBA BBALLBREAKDOWN Basketball Box

BTW. why have chosen to loop through the channel and not give a second menu?

Offline

#358 2020-01-30 16:58:19

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 28,501
Website

Re: Dmenu Hacking Thread

qinohe wrote:

Yes, sure I do see that 'printf "%s\n"'
However I'm looking for a way to get this output

NBA
BBALLBREAKDOWN
Basketball Box

not this

NBA BBALLBREAKDOWN Basketball Box

This is the output I get when I use dmenu -l, otherwise it is presented horizontally, but each item is still \n separated.

qinohe wrote:

BTW. why have chosen to loop through the channel and not give a second menu?

You don't need a second menu: you match the selection from the first against the corresponding URL and hand it to mpv.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#359 2020-01-30 17:07:46

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

lol We are talking besides one another, I want your script to show this:

NBA
BBALLBREAKDOWN
Basketball Box

and it doesn't whatever I try, though even I know it's '\n' separated;)

Yes, you don't need a second menu, though, it's looping trough then, you can't choose video's individually which is also nice BTW. was just wondering..

Last edited by qinohe (2020-01-30 17:08:33)

Offline

#360 2020-01-30 17:11:59

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 28,501
Website

Re: Dmenu Hacking Thread

qinohe wrote:

lol We are talking besides one another, I want your script to show this:

NBA
BBALLBREAKDOWN
Basketball Box

and it doesn't whatever I try, though even I know it's '\n' separated;)

It does behave this way (when -l is used): exactly consistent with how the shell works. There is no mystery here. If you can't reproduce, it is something you have altered/configured.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#361 2020-01-30 17:26:08

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

Oops, I did not even notice the '-i' I normally add a link to my dmenurc and add the '-l'
But since I was testing the script I didn't do that yet. Temporary brain damage I guess  hmm sorry for the noise..

Offline

#362 2020-02-19 20:42:37

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

I saw this post first page of this thread and thought it would be a fun project.
If e.g. you read the new archweb-planet on the site, this tool gives an output thats easier to read;)

Reads RSS1, RSS2 & ATOM1 and produces readable output without mangling inline code fields(mostly).
FOAF and OPML can be read too. Links will be downloaded or opened in a browser like lynx(default)
The XML tag base is big and so I leave it to these formats.

Don't expect it to be perfect with a few lines of sed code

Note: adding characters may be an ongoing process;)
Ask for it or check if the script was updated once in a while, thanks.
Thinking about creating a file containing all or most html tags

Minimal dependencies are:
• dmenu
• curl
• xsel or xclip
• lynx(default) or any other browser

Font type may make a difference, chooce a type that shows all characters!
Tested: DejaVuSansMono does show most if not all chars.

How to get started this script:
Easiest is to create a dmenurc in the root dir. of this script, a sample is shown below.
Store the script in a dir., default '~/.config/dmenu'.
There is a usage menu in the script by starting it with dmenu.

Thats it have fun;) I love to hear from you.

An example dmenurc:

# Used colors: RAL 9003 0n RAL 9004 & choice line  RAL 9004 on RAL 9007 or reversed.
#dmnews='dmenu -i -l 40 -fn DejaVuSansMono-11 -nb #2e3032 -nf #f4f8f4 -sb #2e3032 -sf #8f8f8c'
dmnews='dmenu -i -l 40 -fn DejaVuSansMono-11 -nb #f4f8f4 -nf #2e3032 -sb #8f8f8c -sf #2e2032'

Main script

#!/bin/sh

# Read various local files or remote XML files & newssites with dmenu

# browser, terminal, update time(min.) and the place where you store this script & or data
user=$(logname)

browser='lynx'
term="xterm"
updtime="120"
progdir="/home/$user/.config/dmenu"
datadir="$progdir/data/rss-sites"

[ -f "$progdir"/dmenurc-news ] &&
 . "$progdir"/dmenurc-news || dmnews='dmenu -l 30'

while [ ! -d "$datadir" ] || [ ! -e "$datadir"/xml-sites ]; do
      [ ! -d "$datadir" ] && mkdir -p "$datadir"
      [ ! -e "$datadir/xml-sites" ] &&
       touch "$datadir/xml-sites"
done

trap clean EXIT HUP INT QUIT TERM
clean()
{
  unset news site state choice link clink brows address clip next
  xclip -sel clip /dev/null
  exit 0
}

_necessities() {
  if xclip -version 2>/dev/null; then clip="xclip -sel clip -o"
  elif xsel --version 2>/dev/null; then clip="xsel -bco"; fi
}

_menu() {
  news=$( printf "shownews\nadd-site\ndelete-site\nusage" \
   | $dmnews -l 10 -p 'News:' )
}

_newsmenu() {
  for xml in $datadir/xml-sites; do
    [ -n "$site" ] && exit
    site=$( awk '{print $1}' "$xml" | $dmnews -l 10 -p "$news:" ) || exit
  done
}
_cleanxml() {
  [ "$site" = '' ] && _newsmenu && truncate -s 0 "$datadir/$site"

  sed -e 's/\&amp;/\&/g;s/\&lt;/</g;s/\&gt;/>/g;s/\&apos;/'\''/g;s/\&quot;/"/g;s/\r$//g;
  /<p>/,/<\/p>/s/<br \/>//;/<p>/,/<\/p>/s/<br\/>//;
  s/<br \/>/<p>/g;s/<br\/>/<p>/g;
  s/<\/p>/&\n/g;
  0,/<title>/s//Feed: /;
  0,/<lastBuildDate>/s//&\nLastBuild: /;
  s/<title>/&\n\n---TITLE---  /g;
  s/<dc:title>/Title: /g;
  s/<guid isPermaLink=\"true\">[^>]*>//g;
  s/<!\[CDATA\[//g;s/\]\]>//g;
  s/<link>/&\n\nLink: /g;s/<\/link>/&\n/g;
  /<description>/s//&\n\nContent: &\n/g;
  /<language>/s//&\nLanguage: /g;
  /<copyright>/s//&\nCopyright: /g;
  s/<dc:date[^>]*>/&\n /g;
  s/<dc:creator[^>]*>/&\n\n/g;
  s/<pubDate>/&\n/g;
  s/tag:[^>]*>//g;
  s/<li[^strong>]*strong>/  • /g;
  s/<li>/  • /g;
  s/<guid>[^<\/guid>]*<\/guid>//g;
  s/<premium>[^<\/premium>]*<\/premium>//g;
  s/<[^>]*>//g;
  s/\&hellip;/…/g;
  s/\&rsquo;/’/g;s/\&lsquo;/’/g;s/\&ldquo;/“/g;s/\&rdquo;/”/g;
  s/\&#34;/"/g;s/\&#39;/'\''/g;s/\&#60;/</g;s/\&#62;/>/g;
  s/\&#039;/'\''/g;s/\&#160;/ /g;
  s/\&#x21a9;/↩/g;s/\&#xfe0e;/. ︎./g;
  s/\&#8211;/–/g;s/\&#8220;/“/g;s/\&#8221;/”/g;s/\&#8230;/…/g;
  s/\&amp;/\&/g;s/\&amp;/\&/g;
  s/\t//g;s/^    *$//g' "$datadir/${site}".xml  | fold -s -w135 \
   | sed 's/^[[:space:]]*$//g' >  "$datadir/$site"

  sed -i '/^$/N;/^\n$/D' "$datadir/$site"
  sed -i '/---TITLE/,/^$/s/\//-/' "$datadir/$site"
  sed -i '/---TITLE/,/^$/s/\[/(/' "$datadir/$site"
  sed -i '/---TITLE/,/^$/s/\]/)/' "$datadir/$site"
}

_cleanfoaf() {
  [ "$site" = '' ] && _newsmenu && truncate -s 0 "$datadir/$site"

  sed -e 's/<?[^>]*?>//;
  s/\(<[^="]*="\s*\|"[^="]*="\s*\|[^"\/>]*"\/>\s*\|[^">]*">\s*\|[^" \/>]*" \/>\)//g;
  s/<\/[^>]*>//g;s/<[^\/>]*\/>//g;s/<rdf[^>]*>//g;
  s/<[^>]*>//g;
  s/\&amp;/\&/g;s/\&apos;/'\''/g;s/\&lt;/</g;s/\&gt;/>/g;s/\&quot;/"/g' \
   "$datadir/${site}".xml | fold -s -w135 \
    | sed 's/^[[:space:]]*$//g' >  "$datadir/$site"

  sed -i '/^$/N;/^\n$/D'  "$datadir/$site"
}

_cleanopml() {
  [ "$site" = '' ] && _newsmenu && truncate -s 0 "$datadir/$site"

  sed -e '0,/<title>/s//Feed: /;
  s/\&amp;/\&/g;
  s/\(<outline[^*]*text="\s*\|"[^*]* title="\s*\|"[^*]* xmlUrl="\)/ •• /g;
  s/<[^>]*>//g;
  s/"\/>/\n/g;s/">//g;' "$datadir/${site}".xml \
   | fold -s -w135 | sed 's/^[[:space:]]*$//g' > "$datadir/$site"

  sed -i '/^$/N;/^\n$/D'  "$datadir/$site"
}

_newstate() {
  if [ "$( cksum "$datadir/${site}".xml | awk '{print $1 ,$2}' )" \
   != "$( awk '{print $1 ,$2}' "$datadir/${site}"_sum )" ]; then

     if grep -q '<foaf:' "$datadir/${site}".xml; then
       clink='foaf' && [ -s "$datadir/${site}".xml ] &&
        state='You have news' && _cleanfoaf
     elif grep -q '<opml' "$datadir/${site}".xml; then
       clink='opml' && [ -s "$datadir/${site}".xml ] &&
        state='You have news' && _cleanopml
     else
       clink='xml' && [ -s "$datadir/${site}".xml ] &&
        state='You have news' && _cleanxml
     fi

   else

     if grep -q '<foaf:' "$datadir/${site}".xml; then
       clink='foaf' && state='No news'
       [ -e "$datadir/$site" ] || _cleanfoaf
     elif grep -q '<opml' "$datadir/${site}".xml; then
       clink='opml' && state='No news'
       [ -e "$datadir/$site" ] || _cleanopml
     else
       clink='xml' && state='No news'
       [ -e "$datadir/$site" ] || _cleanxml
     fi

  fi
}

_shownews_one_file() {
  choice=$( $dmnews -p "$state:" < "$datadir/$site" ) #&&
  [ "$choice" != '' ] && link=$( echo "$choice" | awk '{print $1}') || exit
  [ "$link" = 'Link:' ] || [ -n "$link" ] && _brows || exit
}

_shownews() {
  _newsmenu

  [ -z "$site" ] && exit

  _updatexml

  _newstate

  [ -n "$site" ] && cksum "$datadir/${site}".xml > "$datadir/${site}"_sum

  if ! grep -q 'TITLE' "$datadir/${site}"; then
    _shownews_one_file && return
  fi

  while [ -n "$site" ]; do
    if [ "$clink" = xml ]; then
      article=$( sed -n 's/---TITLE---//p' "$datadir/$site" \
       | $dmnews  -p "$state:" ) || exit
    else
      choice=$( $dmnews -p "$state:" < "$datadir/$site" ) || exit
    fi

    [ "$clink" = xml ] &&
     choice=$(sed -n "/$article/,/---TITLE/p;" "$datadir/$site" \
      | sed -e '0,/---TITLE---/ s/---TITLE---  //' \
       | sed -e 's/---TITLE---/Next item: /' \
        | $dmnews -p "$state:" ) || exit

    if [ "$clink" = opml ]; then
      link=$( echo "$choice" | awk '{print $NF}')
    elif [ "$clink" = foaf ]; then
      link=$( echo "$choice" | awk '{print $1}')
    elif [ "$clink" = xml ]; then
      link=$( echo "$choice" | awk '{print $2}')
    fi || exit

    if [ "$link" = 'Link:' ]; then
      _brows
    elif [ "$( echo "$link" | cut -c1-4 )" = 'http' ]; then
      _brows
    elif [ "$link" = 'item:' ]; then

      while [ -n "$link" ]; do
        next=$(echo "$choice" | sed -e 's/Next item:   //')

        choice=$(sed -n "/$next/,/---TITLE/p;" "$datadir/$site" \
         | sed -e '0,/---TITLE---/ s/---TITLE---  //' \
          | sed -e 's/---TITLE---/Next item: /' \
           | $dmnews -p "$state:" ) || exit

        [ -z "$choice" ] &&
        link=$( echo "$choice" | awk '{print $2}' )
        [ "$( echo "$link" | cut -c1-4 )" = 'http' ] && _brows
        link1=$( echo "$choice" | awk '{print $1}' )
        [ "$link1" != 'Next' ] && break
      done
    fi

  done
}

_brows() {
  brows=$( echo "$link" | sed 's/Link: //' )
  [ -n "$brows" ] && eval $term -e "$browser" "$brows" && exit || exit
}

_updatexml() {
  for sites in $site; do
    [ -z "$(find "$datadir" -maxdepth 1 -name "${sites}".xml -mmin -"${updtime}")" ] &&
    curl "$(awk "/$site/"'{print $2}' \
         "$datadir/xml-sites")" -o "$datadir/${sites}.xml"
  done
}

_addsite() {
  _necessities

  address="$( eval "$clip" | $dmnews -p "$news address:" )" || exit
  [ -z "$address" ] && exit

  site="$( echo '' | $dmnews -p "Name for $address?:" )" || exit
  [ -z "$site" ] && exit

  curl "$address" -o "$datadir/${site}".xml
  cksum "$datadir/${site}".xml > "$datadir/${site}"_sum

  printf "%s\n" "$site $address" >> "$datadir"/xml-sites
  _newstate
}

_delsite() {
  _newsmenu

  [ -z "$site" ] && exit

  [ -e "$datadir" ] &&
  sed -i "/$site/d" "$datadir"/xml-sites
  rm "$datadir/${site}".xml \
     "$datadir/${site}"_sum \
     "$datadir/$site" || exit
}

_usage() {
  printf "%s\n" "  Add a site:
  -----------
  Copy a http/s feed address
  Enter 'add-site' in the menu
  Use tab to add the copied site into place
  Or manually add local or remote address
  You're asked to give the site a name

  Shownews:
  ---------
  The added site should be visable in 'shownews'
  You can now read the index of a news page.

  Following a news item is done by using the Enter key
  Return to index is also done by using Enter.

  Going directly to the next news item is done by
  following : 'Next item' at the bottom of each news post.

  There are RSS files that can only be read as one file.
  If so the page page will be shown like this.
  Shownews will close if enter is used!

  Opening a link will close the reader and open a browser
  of your choice

  Closing shownews is done by Escape or Ctrl-c

  Updates:
  --------
  Updates are done if you call the news page
  Default time is set to 120 minutes change the value of this
  variable in this script.

  Be carefull not to set it too low, sites may or will ban
  your IP for being a bot, at least for a while!

  Delete a site:
  --------------
  Enter the 'delete-site' menu.
  Choose a site and hit enter, the site and it's data are removed.


  Change the first 5 variables to your liking:
   'browser term updtime progdir datadir'" \
  | $dmnews -p "$state:"
}

_menu

_pass() {
  [ "$news" = shownews ] && _shownews
  [ "$news" = add-site ] && _addsite
  [ "$news" = delete-site ] && _delsite
  [ "$news" = usage ] && _usage
}
_pass "$@"

edit: new way
edit: check for one file XML's

Last edited by qinohe (2020-03-06 16:12:26)

Offline

#363 2020-02-21 15:28:34

neol09
Member
Registered: 2020-02-13
Posts: 11

Re: Dmenu Hacking Thread

qinohe wrote:

Main script

Well done! I've tried it out and i like it :-)
getting it running took a couple minutes, but i took some notes for you

 1 remove -w flag for compatibility with 'other' dmenu versions

 2 use default alternative for XDG_CONFIG_HOME
     progdir="${XDG_CONFIG_HOME:=$HOME/.config}/dmenu"

 3 check for xclip if xsel is not installed
     :%s/xsel -bco/"$clip"/g
     if   xclip -version 2>/dev/null; then clip="xclip -sel clip -o"
     elif xsel --version 2>/dev/null; then clip="xsel -bco"; fi

 3.1 Might aswell bring up support for wget at this stage

 4 handle folder creation on launch to prevent spam from checking feeds
   after you've deleted them all or as in my case on first launch

 4.1 clean() attemped to write to a non existant file
     same scenario, check if the file exists before running checksum
     related to #5

 5 Chaining dmenu prevents smooth termination
     address="$( $clip | $dmindex -p "$news address:")"
       mangles ctrl+c
     address="$( $clip | $dmindex -p "$news address:")" || exit
       doesn't mangle ctrl+c

 6 echo "$choice" | awk '{print $1}'
   can be shortened to awk '{print $1}' <<< "$choice"
                    or cut -d' ' -f1 <<< "$chocie"
                 or or "${choice%% *}" in bash ( bash only? )

 7 no need to [ "$address" = '' ]; just [ "$address" ]

 8 you're launching _menu right after defining it, had me running in circles
   around the bottom of the script for a moment there :-) should skip that
   function if $1 is one of the options for _pass, no?

 9 isn't >| a bashism? this script is #!/bin/sh

10 for some reason scrolling through a modest length post ( like your last
   post in this thread  ) introduced noticable lag in dmenu
   Much as that a downside for dmenu i think it could be an upside for you,
   Could break up the feed into posts? no :)

11 Heh all you're *really* missing is something along the lines of a while
    true loop and you'll be golden.

and ofcourse, good job with sed. I'll have to go over that bit some other time.

Offline

#364 2020-02-21 17:34:37

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

Thanks @neol09 wink very happy you tried it, and glad you like it.
I have tried a few RSS readers and most of them screw inline code-fields or completely mess up readability.

I will have to take some time to update everything and test it all.
One thing I don't quite get though why "_menu" got you running circles as it's passed before "_pass"
I will however see if I can implement "_menu" with some other logic...

Also didn't know ">|" is a bashism, thought it was sh compliant...

Then 10 & 11 I had no issues scrolling trough the thread and I work on a tiny board as a daily system.
I don't know if it's worth it to show every item as a separate one and have an index but I will have a look at it after I went trough all this first..

If you're interested ; Upboard version1 https://up-board.org/up/specifications/

Offline

#365 2020-02-23 21:45:24

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

Again, @neol09, Thanks for your extensive list there were some very valid pointers in it. If you're the sole user of a script you tend work around it's shortcomings, I was already using it for a little while.
It now don't matter if you exit the script using Enter Esc or Ctrl-c at any point.
I created the list again with the updates or not and gave reasons why I did not implement it.
Could be I have forgot something still, please let me know, Thanks;)

•  Q 1 remove -w flag for compatibility with 'other' dmenu versions
•  A 1 removed -w width so dmenu users can use it too.

• Q 2 use default alternative for XDG_CONFIG_HOME
       progdir="${XDG_CONFIG_HOME:=$HOME/.config}/dmenu"
• A 2  XDG removed added user and dir.

• Q 3 check for xclip if xsel is not installed
     :%s/xsel -bco/"$clip"/g
     if   xclip -version 2>/dev/null; then clip="xclip -sel clip -o"
     elif xsel --version 2>/dev/null; then clip="xsel -bco"; fi
• A 3 xclip or xsel was a minor adjustment, good call

• Q 3.1 Might aswell bring up support for wget at this stage
• A 3.1 wget is a different story, local files('file://') must be able to be used too, curl is best suited for this task.
        Unless of course you know a way to implement this with wget in a sane way...

• Q 4 handle folder creation on launch to prevent spam from checking feeds
      after you've deleted them all or as in my case on first launch
• A 4 agreed

• Q 4.1 clean() attemped to write to a non existant file
        same scenario, check if the file exists before running checksum
        related to #5
• A 4.1 brought some new logic into place for clean()

• Q 5 Chaining dmenu prevents smooth termination
      address="$( $clip | $dmindex -p "$news address:")"
       mangles ctrl+c
      address="$( $clip | $dmindex -p "$news address:")" || exit
       doesn't mangle ctrl+c
• A 5 agreed

• Q 6 echo "$choice" | awk '{print $1}'
      can be shortened to awk '{print $1}' <<< "$choice"
                    or cut -d' ' -f1 <<< "$chocie"
                 or or "${choice%% *}" in bash ( bash only? )
• A 6 '<<<' 'here document' ; you can't use this in POSIX sh

• Q 7 no need to [ "$address" = '' ]; just [ "$address" ]
• A 7 must check existence so '-z'

• Q 8 you're launching _menu right after defining it, had me running in circles
      around the bottom of the script for a moment there :-) should skip that
      function if $1 is one of the options for _pass, no?
• A 8 You can't pass '$1' in '_pass' it breaks the script...

• Q 9 isn't >| a bashism? this script is #!/bin/sh
• A 9 agreed, removed '|>' though, I thought it is POSIX sh, '-o' is cleaner and part of curl

• Q 10 for some reason scrolling through a modest length post ( like your last
       post in this thread  ) introduced noticable lag in dmenu
       Much as that a downside for dmenu i think it could be an upside for you,
       Could break up the feed into posts? no smile
• A 10 no problems scrolling long documents here using dmenu or dmenu2
       maybe in a later state if I polished things for a while I will think of breaking up posts...

• Q 11 Heh all you're *really* missing is something along the lines of a while
       true loop and you'll be golden.
• A 11 there is a while loop now to check for the files, but is that what you meant?

Last edited by qinohe (2020-02-24 17:21:45)

Offline

#366 2020-02-28 20:42:56

accy
Member
Registered: 2019-12-23
Posts: 4

Re: Dmenu Hacking Thread

zf wrote:

To re-iterate, I want the functionality of C-Y to be C-v, not C-V. Any help is much appreciated.]

youu dont need to duplicate code like you're doing, just add the switch case without any return or break, like so

		case XK_v:
		case XK_y: /* paste selection */
		case XK_Y:
			XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
			                  utf8, utf8, win, CurrentTime);

and this works fine for me. did you by chance forget to recompile?

Offline

#367 2020-03-04 16:55:40

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

The dmenu xml reader (#362) has got an overhaul which have changed it's working quite a bit.

The news pages now have an index of which each item shows a single news post.

Read usage in the menu to see exactly how it works, hope you like it..

edit: added way to open one file XML, like VuXML

Last edited by qinohe (2020-03-06 16:14:12)

Offline

#368 2020-03-15 19:25:22

cirrus
Member
From: Glasgow Scotland
Registered: 2012-08-24
Posts: 291
Website

Re: Dmenu Hacking Thread

Hi
    I could use some help with a wee script i been playing with, i am by no means a coder in any shape or form, so im sure my script could be sanitized, i have gotten it to work almost the way i want, the only issue im having is how to close feh once the track is finished, as is im using feh -A flag to close the feh window when clicked on.

here is my mish mash

#!/bin/bash
url=$(cat /home/cirrus/Documents/mp3.txt | cut -c 31-   | shuf |sed 's/....$//' | bemenu --tf "#028e9b" --tb "#1c1c1c" --nb "#303030" --nf "#f5e5d5"  --hf "#d79921" --hb "#191919" --sb "#080808" --sf "#d7ff00" -l 17 -P  Play:➤ )


ffmpeg -i  "/home/cirrus/Music/mp3/$url.mp3" /home/cirrus/cover.png -y && feh -P  -. -g 150x150+1192+597 -A 'rm /home/cirrus/cover.png' /home/cirrus/cover.png | mpg123  "/home/cirrus/Music/mp3/$url.mp3" & 

exit

fehartmp3
I pasted path of mp3 directory into firefox then used the Link Gopher extension to snarf all the paths of my mp3's then saved them to a .txt file, and as you can see i killed a cat [sic].
Any help on cleaning this up and/or how to rm ~/cover.png && exit feh after track completion would be great, thanks in advance.
P.S i am aware

mpv --geometry=150x150+1192+597 --autofit-smaller=150x1500 "/home/cirrus/Music/mp3/$url.mp3"

would suffice but id rather use the ffmpeg method to show embedded album art.
Regards:
cirrus

Last edited by cirrus (2020-03-15 19:56:44)


Registered Linux User #544546
   Time you enjoyed wasting was not wasted. --John Lennon.

Offline

#369 2020-03-15 21:54:48

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

@cirrus, Haven't had time to try but I have a question; what is 'shuf', or did you mean shuffle?

I'm sure you don't need to kill the cat , bring it to the animal pension instead lol (you can get rid of it yeah for sure)

Also it's worthwhile to mention needed dependencies..

Offline

#370 2020-03-15 22:38:34

2ManyDogs
Forum Moderator
Registered: 2012-01-15
Posts: 3,053

Re: Dmenu Hacking Thread

qinohe wrote:

@cirrus, Haven't had time to try but I have a question; what is 'shuf', or did you mean shuffle?

https://linux.die.net/man/1/shuf
https://www.gnu.org/software/coreutils/ … ation.html

Offline

#371 2020-03-15 22:41:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,905
Website

Re: Dmenu Hacking Thread

No, he meant shuf.  I didn't even know shuffle existed.  Now that I do, I can't imagine why it does.  shuf is a shell built in (edit: I guess not in bash, but it is provided by coreutils as it's a POSIX tool).

Cirrus, I can't make heads or tails of what the ffmpeg et al line does, but for the first line, ditch the text file and just use find:

find /path/to/mp3s/ -type f -name '*.mp3' | shuf ...

Last edited by Trilby (2020-03-15 23:09:48)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#372 2020-03-15 22:45:52

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

Well how about that, I knew shuffle exists but I didn't know about shuf, coreutils even..;)

edit: @Trilby, he extracts an image from the *.mp3 with ffmpeg, shows it with feh and later deletes it and plays the file with mpg123

Last edited by qinohe (2020-03-15 22:50:46)

Offline

#373 2020-03-15 23:09:07

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,905
Website

Re: Dmenu Hacking Thread

Yes, but why would those steps be in a pipeline?  Why is the rm command a parameter and what is piped to mpg123.  None of that seems necessary.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#374 2020-03-15 23:19:41

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,011

Re: Dmenu Hacking Thread

Agreed, but beats me, it's his script. I was simply telling in words what I saw after you said heads or tails;)

edit: He's using 'feh -A' (action) and uses a shell command to remove the extracted picture...

Right so I had some time to try your script and it's very ugly, really sad

I now get the pipe to mpg123... but it will only work if there's embedded art...

Loose that feh crap or think out a working solution...
Here's a working based on your script without feh btw. & based on dmenu.
I used find as proposed by Trilby.

 #!/bin/bash
  
[ -f "$HOME"/.config/dmenu/dmenurc ] &&
 . "$HOME"/.config/dmenu/dmenurc || dmuse='dmenu'
  
dir=("$HOME"/Music
     "$HOME"/Nextcloud/Music)
  
file=$(find "${dir[@]}" -maxdepth 6 -type f -name '*.mp3' \
 | shuf | sed 's/....$//' | $dmuse -l 30 -p  "Play:➤" )
  
mpg123 "${file}.mp3" &

Last edited by qinohe (2020-03-16 05:20:54)

Offline

#375 2020-03-16 14:55:18

cirrus
Member
From: Glasgow Scotland
Registered: 2012-08-24
Posts: 291
Website

Re: Dmenu Hacking Thread

Thank you all for taking the time to respond to my spaghetti mess, and for the useful tips.
i apologise if i posted in the wrong place as im aware this is not a support thread.
kind regards

[edit]

qinohe wrote:

I now get the pipe to mpg123... but it will only work if there's embedded art...

i  use a rubygem named fancy_audio which makes embedding art a breeze w/ the -all flag.

qinohe Thanks your more sane script with the slight edit

#mpg123 "/home/cirrus/Music/mp3/${file}.mp3" &
mpv --geometry=150x150+1192+600 --autofit-smaller=150x150 "/home/cirrus/Music/mp3/${file}.mp3" &

makes it do exactly as i hoped.

Last edited by cirrus (2020-03-16 21:22:53)


Registered Linux User #544546
   Time you enjoyed wasting was not wasted. --John Lennon.

Offline

Board footer

Powered by FluxBB