Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: [SOLVED] dmenu output question (Read 1036 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[SOLVED] dmenu output question

I am trying to make a keybinding script, called F2
Originally, this was just a simple echo, but echo outputs only on terminal and is impossible to test on keybindings
So, to confirm the script works, I changed it on
Code: [Select]
lf /dev
(could be any file location, but the above test folder exists)

The script has +x and is detectable by both dmenu and terminal.
Typing in terminal
Code: [Select]
F2
Pops up the file location as intended.

However, it doesn't do anything when invoked via dmenu (and theoritically the keybinding)

Any idea what change I need to do? I thought my keybinding configuration was just bugged originally, as the script ran on terminal but not on keybinding, but to not run on dmenu, even though it detects it, is surely weird

Re: dmenu output question

Reply #1
What exactly is your script trying to do? Is it just trying to have dmenu use some output text as an input? Or are you trying to enter something into dmenu and have it print out somewhere?

If you're trying to do the former, dmenu just takes newline delimited std. in. to display the text. If you're trying to return something you enter into dmenu? Where do you want it returned? The easiest way to return it to your screen would probably be to wrap the dmenu part of your script in
Code: [Select]
notify-send

I can't really give you any specific advice without further detail.

Re: dmenu output question

Reply #2
Quote
What exactly is your script trying to do?
Open lf, and go to a certain file location, hence its full code is
Code: [Select]
#!/bin/sh

lf /dev
because if that works, then it works for any location

Re: dmenu output question

Reply #3
Isn't it much easier just to type
Code: [Select]
lf /some/dir
in the shell? Since you are already using minimal and/or suckless tools, it is the suckless way to not complicate things.

(As a side note, file managers in general are not suckless, as standard Unix commands such as cd, cp, ls, mv and rm are more minimal and follow the Unix philosophy better.)

dmenu is a program which:
  • reads multiple lines of text from stdin until EOF,
  • creates a graphical menu out of those lines, allowing the user to select one item (=line of text) or type in a line of text, and
  • outputs the resulting line to stdout.
That's it. Nothing more, nothing less than that.

Re: dmenu output question

Reply #4
Open lf, and go to a certain file location, hence its full code is
Code: [Select]
#!/bin/sh

lf /dev

Whilst I share Strajder's sentiment on the matter (I don't really use file managaers much anymore tbh)

To do what you ask should be as simple as

Code: [Select]
#!/bin/sh

dir=$(ls ~/ | dmenu -p "Enter Directory: ")
lf "$dir"

 

Re: dmenu output question

Reply #5
Quote
Isn't it much easier just to type
Code: [Select]
lf /some/dir
in the shell? Since you are already using minimal and/or suckless tools, it is the suckless way to not complicate things.

The end goal is to have my Super+Fnumber keys go to certain locations, which are often lengthy (e.g. /harddrive/user/old/videos or /harddrive/user/old/pdf)
Typing these on terminal everytime is very annoying and consumes plenty of time daily
Less so when I can open terminal to type F2+enter, but that's in total 4 button presses (excluding Shift+Super), when it could be just 1.

The above script F2, works on the terminal. But when I binded F2 key via windows manager (dwm), it didnt work, so I thought that my windows manager was bugged. Then, one day, I tried running F2 script via dmenu, and it didn't work either, so its not a keybinding bug, my script is just wrong. And I instantly posted this thread because I am a linux newbie and search engine didn't help on solutions

The post above me confirmed its not a dwm bug but my script is bugged/wrong
Code: [Select]
dir=$(ls /harddrive/user/old/videos | dmenu -p "Enter Directory: ")
lf "$dir"
instantly works by pressing F2 and browses my videos and folders - but does not open lf!!

So I guess the main title of this thread is off-topic, as it is more related to dwm and lf, but how do I make F2 create a lf instance/window and go at a certain location?
Update: I did it. So, lf needs terminal to run, so I simply put in my dwm's config.h on the F2 keybinding
`SHCMD(TERMINAL " -e lf /harddrive/user/old/videos")`

Thank you very much. Especially that codepart above, which confirmed lf does not open via dmenu. Now I can finally move around my computer without restriction <3

Quote
Whilst I share Strajder's sentiment on the matter (I don't really use file managaers much anymore tbh)
What do you use to browse your computer's files? E.g. to move browser's downloads somewhere else

Re: [SOLVED] dmenu output question

Reply #6
Typing these on terminal everytime is very annoying and consumes plenty of time daily
Just the amount of text in your last post exceeds the length of most pathnames.

Most shells support some form of autocompletion by pressing the Tab key.

Re: [SOLVED] dmenu output question

Reply #7
What do you use to browse your computer's files? E.g. to move browser's downloads somewhere else
99% of the time I know what the file name is and where it is located, so I'll pull up a terminal (sometimes fullsize, sometimes scratchpad, depends on specifically what I'm doing) and I'll just cd to where I need to go.

It probably helps that I've prioritised having important stuff that I need often in locations where the directory name is the only possible tab-completion (or at least I only have to type 1-2 characters to get to that point) so I can just spam tab instead of typing.

With downloads, if it's a compressed file of some type, I'll just download it into my Downloads folder and extract it to where I want it to go.

Now that being said, I do have ranger set up with keybindings set up for common directories, but unless I'm desperately in need of every last second (such as when teaching a class) I don't really use it tbh.