How to make clicking/running directory execute a file?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

How to make clicking/running directory execute a file?

#1 Post by sunburnt »

RoxApps, or AppDirs do this, but I find no info. on the mechanism.
File associations it seems are only for files... Makes sense.

# So how to setup dir. associations?

The dir. has an extension: .sqApp
Want running the dir. to run the file SqApp inside it.

CLI would be the best because then a GUI click would be easy to setup.

For GUI I think I`ll have to pick a file browser like Xfe and mod it to work.
I dislike "Open With", never use it, I need control of click and Rt. click.

User avatar
ravensrest
Posts: 365
Joined: Fri 22 Feb 2008, 16:43
Location: Grants Pass, Oregon

#2 Post by ravensrest »

I am not sure how you might do it with a mouse click, but if it is always the same directory and same file, then you could write a very simple 2-line script to do it:

CD (desired directory)
exec (desired file)

You could run it from CLI or make it an icon on the pinboard.

BS

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#3 Post by Karl Godt »

I think the execute file is named "AppRun" for rox and maybe needs this additional AppInfo.xml .

If you want to click in the terminal : Are you referring to something like midnight commander ?

If so, did you get mouse support to work (by gpm or whatever) ?

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: How to make clicking/running directory execute a file?

#4 Post by L18L »

sunburnt wrote:...For GUI I think I`ll have to pick a file browser like Xfe and mod it to work.
I dislike "Open With", never use it, I need control of click and Rt. click.
If you take file browser rox then everything is ready.

right click > menu
left click > AppRun is executed

working example: gparted

# ls -la
insgesamt 16
drwxr-xr-x 2 root root 4096 Jun 13 19:00 .
drwxr-xr-x 22 root root 4096 Jun 13 17:52 ..
-rwxr-xr-x 1 root root 125 Jun 13 17:47 AppInfo.xml
lrwxrwxrwx 1 root root 27 Jun 13 18:58 AppRun -> ../../../sbin/gparted_shell
-rw-r--r-- 1 root root 2903 Jun 13 19:00 .DirIcon
#


AppInfo.xml:

Code: Select all

<?xml version="1.0"?>
<AppInfo>
  <Summary>GParted</Summary>
  <Summary xml:lang="de">Partitionen-Editor</Summary>
</AppInfo>
The answer to your question: look into rox sources 8)
Attachments
gparted_in_rox_apps.png
gparted integrated into rox/apps
(17.19 KiB) Downloaded 442 times

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#5 Post by sunburnt »

Hi ravensrest; I forgot to mention it`s stand-alone like the ROX Apps.
The point is to have the dir. be the only thing required to run the app.

Hey Karl; No, not click in CLI just GUI. The CLI need is like the mime Q.
I`m looking for a method to get running a dir. to exec. a file inside it.
# Appinfo.xml only has app. info.:

Code: Select all

<?xml version="1.0"?>
<AppInfo>
  <Summary>Abiword text editor</Summary>
</AppInfo>
I saw a patch for Bash-201 someone wrote in C that makes this happen.
Too old to be of any use now.

Hi L18L; Yeah, I know about Rox and Gobo Linix, but I don`t care for ROX-Filer.
I like the Xfe / Win.Explorer type GUI.
One would hope that there is a Rox exec. or lib. that does the work.

# But the real Q is... How to get Bash to do it? Then the GUI is a snap.
.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#6 Post by L18L »

sunburnt wrote:...# But the real Q is... How to get Bash to do it? Then the GUI is a snap.
.

Code: Select all

# rox /usr/local/apps/gparted/
# 
has launched gparted

(give a directory to a web server and it will take a default file)

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#7 Post by sunburnt »

Hi L18L; The file rox is a shell script, I can do that too, but that`s not it.
I don`t want to have to run a shell script to run another shell script.

I put an AppRun file in a dir. and ROX-Filer changed the icon, so that`s it.

Bash in a VT does nothing with RoxApp dirs. Only running the file works.
I`d be happy if Bash would recognize a dir. by extension like a file.
I can easily write a script to do this, but it`s not what I had in mind.

If Bash had sockets, behaviors could be added without patching it.

But I will probably have to settle for writing a AppDir script for Xfe.

Bruce B

#8 Post by Bruce B »

I`d be happy if Bash would recognize a dir. by extension like a file.
Bash can recognize directories by at least two methods I know of.

1) the test command using the -d switch. For details type help test on the CLI

2) an ls file listing output. Example below:

ls -l | grep ^d would display only the directories

3) I suppose there are other ways I just don't know about.

~~~~~~~~~~~~

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#9 Post by Karl Godt »

Just a short idea :

how about a function in .bashrc ?

like

Code: Select all

toggle_mybash(){
something=1
while [ $something ];do
read -p "Enter [command] : # " ENTRY
[ "$ENTRY" ] || continue
EVTL_COMMAND=${ENTRY%% *}
EVTL_PARAMETERS=${ENTRY##* }
if test `which $EVTL_COMMAND` ;then
$EVTL_COMMAND "$EVTL_PARAMETERS"
elif test -d "$ENTRY" ;then
[ -x "$ENTRY"/AppRun ] && "$ENTRY"/AppRun
elif test -f "$ENTRY" ;then
"$ENTRY"
elif test "`type $ENTRY`" ;then
$ENTRY
elif test "$ENTRY" ;then
"$ENTRY"
else
"$ENTRY"
fi;done; };toggle_mybash
which can be left/escaped by "return" or "exit" command.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#10 Post by sunburnt »

Hi Bruce B; The thought was that Bash would recognize an "extension" on a dir. just like it does for a file.
Then this would allow for mime behavior with dirs. as well as files.
Of course Bash doesn`t really use mime any way, but it could / should.
That`s why I was dreaming of Bash plug-ins. :idea:

Karl; This comes about as close as I think it can get.
I was thinking maybe something could be done in profile.local or .bashrc.

Q: Wouldn`t all the tests after running AppRun be easier with just "else"?

I think this could work for the junction hack I made, and Bash mime too!
I`ll see how the whole idea pans out and let you know.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#11 Post by Karl Godt »

i think that this can implemented in the bash source code . I am guessing the soure already uses a C case loop for this like i have often seen in main()s parsing parameters .

Don't know if you want a full bash or just your_bash .

which command seems not to work on shell buitins like return, here type is needed .

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#12 Post by sunburnt »

I tried your function and it works of course, but console is plain-vanilla.
There`s no command history and probably other behaviors are lost too.
But I`m thinking that a special sh fork could run the loop and be used?
This would keep Bash from being hijacked and made partly unusable.

Code: Select all

sh-4.1# /mnt/sdb3/AppDir/Fox-1.6.45
sh: /mnt/sdb3/AppDir/Fox-1.6.45: is a directory
sh-4.1# bash
sh# ^[sddfsf: command not found ............... bash not taking arrows, etc.
sh# : type: 
sh# 
sh# ^[[A^[[B
bash: type: : not found
bash: : command not found
sh# /mnt/sdb3/AppDir/Fox-1.6.45 .................. command works
sh# 
Notice that the sh shell didn`t respond, but entering the bash shell did.

### Here`s your script I modded and added to .bashrc

Code: Select all

shmod(){					# intercept commands and process them
	while :
	do
		read -p "sh# " ENTRY
		[ "$ENTRY" ] || continue
		EVTL_COMMAND=${ENTRY%% *}
		EVTL_PARAMETERS=${ENTRY##* }

		if test `which $EVTL_COMMAND` ;then
			$EVTL_COMMAND "$EVTL_PARAMETERS"
		elif test -d "$ENTRY" ;then
			[ -x "$ENTRY"/AppRun ] && "$ENTRY"/AppRun
		elif test -f "$ENTRY" ;then
			"$ENTRY"
		elif test "`type $ENTRY`" ;then
			$ENTRY
		elif test "$ENTRY" ;then
			"$ENTRY"
		else
			"$ENTRY"
		fi
	done; 
}
shmod
I can write a C exec. in BaCon of this and it will be better.
The code could be added to Bash`s daemon loop, but I wouldn`t know how...
But I think more development on it is needed.

I`m going to try it for mime and with my junction hack.
This shell mod and mime are Bash items, but the junction is really a kernel item.

# I`m taking my boy to see the movie: The Avengers ( action and funny! ).
So I`ll be gone for 4 hours or more.

Thanks for the point in the right direction Karl, I`m hopeful about this!

Ihr Freund... Terry B.
.

Post Reply