You are not logged in.

#1 2012-12-24 15:36:38

Gullible Jones
Member
Registered: 2004-12-29
Posts: 4,863

dirpipe.sh, a directory pipe menu for Openbox

#!/bin/sh                                                                      
# dirpipe.sh: generates an Openbox pipe menu of directories                    

terminal="uxterm"
user_shell="/bin/bash"
self="$0"
current_dir="$1"
if [ ! $current_dir ]; then current_dir="$HOME"; fi


echo "<openbox_pipe_menu>"
cat <<END                                                                      
<item label="Shell here..."><action name="execute"><execute>$terminal -e "cd '$current_dir'; $user_shell"</execute></action></item>                          
<separator/>                                                                   
END                                                                            
cd "$current_dir"
for i in *; do
    if [ -d "$i" ]; then
        cat <<END                                                              
<menu id="$i" label="$i" execute="$self '$current_dir/$i'"/>                   
END                                                                            
    elif [ -e "$i" ]; then
        cat <<END                                                              
<item label="$i"><action name="execute"><execute>mimeopen -n '$current_dir/$i'</execute></action></item>                                                     
END                                                                            
    fi
done
echo "</openbox_pipe_menu>"

It accepts one argument, the directory which it creates an entry for; if no argument is given, or the directory doesn't exist, it defaults to your home directory. Files of all types are opened with mimeopen (from perl-file-mimeinfo). The terminal and shell can of course be changed be editing the beginning of the script.

Be warned that this script calls itself recursively, so you may get a lot of sh processes when scrolling through deeply nested directories! Not sure if there's any way to fix that, unfortunately.

Edit: removed superfluous IFS line.

Last edited by Gullible Jones (2012-12-24 15:37:34)

Offline

#2 2012-12-24 15:42:56

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: dirpipe.sh, a directory pipe menu for Openbox

current_dir="$1"
if [ ! $current_dir ]; then current_dir="$HOME"; fi

Could be

current_dir=${1:-$HOME}

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2012-12-24 16:04:11

Gullible Jones
Member
Registered: 2004-12-29
Posts: 4,863

Re: dirpipe.sh, a directory pipe menu for Openbox

Less readable to those new to shell scripting (like me, har har). Thanks though.

Offline

#4 2012-12-24 16:32:27

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: dirpipe.sh, a directory pipe menu for Openbox

Out of curiosity, are you aware of ObFileBrowser?


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#5 2012-12-24 20:46:04

Gullible Jones
Member
Registered: 2004-12-29
Posts: 4,863

Re: dirpipe.sh, a directory pipe menu for Openbox

If I was, I'd forgotten about it. I do know of another one written in Python though.

(Reinventing the wheel is fun. And sometimes educational.)

Offline

#6 2012-12-25 09:30:44

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: dirpipe.sh, a directory pipe menu for Openbox

Gullible Jones wrote:

(Reinventing the wheel is fun. And sometimes educational.)

Indeed. I've done it several times myself, often just to explore an idea.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB