Comments (16)
Thanks, I will do that. I will reopen this issue if I have problems.
from scripts.
That's because item1\nitem2
does not exists thus test -e "$newt"
does not pass. You will need to loop between single items and handle them separately. For example:
for item in $sel; do
Do something with $item...
done
You also need to take into account several things like:
$target
must updated only when a single directory is selected- what if both a file and a directory are selected?
- what if two or more directories are selected?
- likely more check...
I cannot code that for you right now. Since this is not related to dbrowse
but rather it's about shell scripting I'll closse this issue. Please ask for help on Stack Overflow or other related communities. Feel free to contact me on IRC if you wish, I'm on libera.chat as clamiax
. Thanks!
from scripts.
Unluckily this version has also several issues. I will push an update which should hopefully handle all corner cases.
from scripts.
You cannot implement multi-selection. All you can do is to support dmenu
variants which are patched with this feature. In addition you may write a note on the README
to inform the users about that.
from scripts.
I already applied the multiselection patch and it works for me. So if I do ls | dmenu
I can select my Documents
and Downloads
directories and the output will be:
Documents
Downloads
But for some reason, it does not work with this script.
If I select two things, it will return me to the Dmenu prompt again.
from scripts.
That's because sel
is assumed to contain a single item. You will need to change the script by managing multiple items separated by a newline.
from scripts.
Sorry I do not know how to prevent sel
from assuming there is one item. Maybe it's here:
if [ ! -d "$target" ]; then
echo "$target"
exit 0
fi
But let's say I select two items, the output should be item1\nitem2
. Why would echo
have a hard time printing that?
from scripts.
Thank you for the help. I will ask on unix.stackexchange.com or stackoverflow.com if I still have difficulties.
from scripts.
Update: I managed to implement multi-selection support.
- $target must updated only when a single directory is selected
- what if both a file and a directory are selected?
- what if two or more directories are selected?
- likely more check...
- yep, the $target is only updated when a single directory is selected
- it will throw an error and exit the program, although I will probably create an error message to make it more user-friendly
- same as above
- it works exactly as expected, no issues
I did not need to add any for
loops. I just had to modify the if
statements and also add new ones. The only real difficulty I had is with the program
option. In my dfm
project, you can pass the --program
option to open the file(s) in the default program for the file type. For example, if you select a .mkv
file, it will use your default media player. This uses xdg-open
from the xdg-utils package. But xdg-open
only accepts one argument, so it will not work if more than one file is selected. I had to work around this by creating a complicated command that allows xdg-open
to open more than one file. See this post on Unix Stack Exchange.
Would you like me to submit a pull request to this repository? I see that multisel is in the TODO of the dbrowse
script. It will add less than 10 single lines of code to the script.
from scripts.
There is no place in dbrowse
for complex shell hacks, to hardcode file handling (xdg suite, etc.) or depending on GTK applications like gtk-launch
. These are all features for another tool.
I expect dbrowse
to do one thing and do it well: read items from dmenu
, resolve them to full paths and navigate to or print them.
For instance, this is how I expect multisel to be implemented:
$ ./dbrowse # I will go to /tmp/test then select two files: foo and bar
/tmp/test/foo
/tmp/test/bar
I will accept PRs if they respect the phylosophy behind dbrowse
.
from scripts.
Oh, xdg-utils and gtk-launch are not required for dbrowse. The reason they are dependencies for dfm is that dfm supports opening the files selected with the default program. So on dbrowse, the first code block will change to the second:
if [ -e "$newt" ]; then
target="$newt"
if [ ! -d "$target" ]; then
echo "$target"
exit 0
fi
fi
if [ -e "$newt" -o $(echo "$sel" | wc -l) -gt 1 ]; then
target="$newt"
if [ ! -d "$target" ]; then
echo "$target" | sed 's@^'"$PWD"/'@@' | sed 's@^@'"$PWD"/'@'
exit 0
else
PWD="$target"
fi
fi
If this change is acceptable to you, I will submit a PR. If not, that is fine. The sed
command in this case is a bit gimmicky.
from scripts.
You should not test -e $newt
before know if it's a filename or a list of values separated by newline. Also the sed
workaround to fix the target don't always works:
$ cd /tmp/test ; ./dbrowse /tmp # pick file `foo` and directory `bar`
/tmp/test//tmp/foo
/tmp/test/bar
A better approach would be:
- count the items
- if it's only 1 and it's a directory then update
$target
- otherwise for each item print the full path, finally exit
That should be enough.
from scripts.
Alright so this one should work without any issues:
if [ `ls | wc -l` -ge 1 ]; then
target="$newt"
if [ ! -d "$target" ]; then
echo "$target" | head -1 && echo "$target" | tac | head -n -1 | tac | sed 's@^@'"$PWD"/'@'
exit 0
else
PWD="$target"
fi
fi
This is the final version I'm making. Tell me if it's okay and I'll submit a PR. Otherwise, I'll stop commenting.
from scripts.
I checked your latest commits and your multi-selection support looks good. I will implement it to DFM if you do not mind.
from scripts.
I checked your latest commits and your multi-selection support looks good. I will implement it to DFM if you do not mind.
But as for the $NEWLINE
variable, does NEWLINE="\n"
not work? It seems like a better way of writing it.
Edit: Nevermind I checked it and it NEWLINE="\n"
does not work.
from scripts.
@amarakon Feel free to use the code as you wish.
from scripts.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scripts.