WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Xfe :: Executing scripts on files via right click / context menu  (Read 4645 times)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Xfe (X File Explorer) provides a handy new feature (since v 1.35) which I use to pack TCZ extension and core.gz.

Xfe version 1.37 (xfe.tcz) is available for TC 5.x (x86).

As I tend to be quite lazy and often forget about parameters for some programs, this feature makes it very easy for me to modify TinyCore to my likings.

Whenever I modify or create a TCZ or core.gz, I first copy it to  /tmp , extract it via executing the respective script via right click menu, then I make the changes (using an additional Xfe window as root if necessary) and repack it (as normal user).

From the DOCS: http://roland65.free.fr/xfe/index.php?page=docs
Quote
Scripts

Custom shell scripts can be executed from within Xfe on the files that are selected in a panel. You have to first select the files you want to proceed, then right click on the file list and go to the Scripts sub menu. Last, choose the script you want to apply on the selected files.

The script files must be located in the ~/.config/Xfe/scripts folder and have to be executable. You can organize this folder as you like by using sub-folders. You can use the Tools / Go to script folder menu item to directly go to the script folder and manage it.

Here is an example of a simple shell script that list each selected file on the terminal from where Xfe was launched:
#!/bin/sh
for arg
do
/bin/ls -la "$arg"
done

You can of course use programs like xmessage, zenity or kdialog to display a window with buttons that allows you to interact with the script. Here is a modification of the above example that uses xmessage:
#!/bin/sh
(
echo "ls -la"
for arg
do
/bin/ls -la "$arg"
done
) | xmessage -file -

Most often, it is possible to directly use Nautilus scripts found on the Internet without modifications.


I use the following scripts for core.gz:

~/.config/xfe/scripts/core.gz/extract
Code: [Select]
#!/bin/sh

for arg; do
xterm -e $HOME/.local/bin/core-gz-extract $arg
done

Which in turn executes another script (so I can use those scripts even without Xfe if needed)

~/.local/bin/core-gz-extract
Code: [Select]
#!/bin/sh


if [ ! -f $1 ]; then
popup "Not a file: $1"
exit 1
fi

core_gz=$1
core_gz_no_ext=${core_gz/.gz/}

mkdir $core_gz_no_ext

if [ ! -d $core_gz_no_ext ]; then
popup "Could not create dir: $core_gz_no_ext"
exit 1
fi

cd $core_gz_no_ext
zcat $core_gz | sudo cpio -i -H newc -d


--
When I'm done with my modifications ... right click -> pack

~/.config/xfe/scripts/core.gz/pack
Code: [Select]
#!/bin/sh

for arg; do
xterm -e $HOME/.local/bin/core-gz-pack $arg
done


~/.local/bin/core-gz-pack
Code: [Select]
#!/bin/sh

if [ "${USER}" == "root" ]; then
echo "Don't run this as ROOT!"
popup "Don't run this as ROOT!" 2>/dev/null
exit 1
fi

if [ ! -e /usr/local/tce.installed/advcomp ]; then
xterm -e tce-load -i advcomp.tcz
fi

if [ ! -d $1 ]; then
popup "Not a directory or doesn't exist: $1" 2>/dev/null
exit 1
fi

core_gz=$1.gz
core_gz=${core_gz##*/}

cd $1
echo -n "Doing stuff, wait... "
sudo find | sudo cpio -o -H newc | gzip -2 > ../$core_gz &
rotdash $!
echo "OK."
cd ..
echo -n "Doing even more... "
advdef -z4 $core_gz &
rotdash $!
echo "Done."

Then I can copy it back (I'm doing this manually on purpose in case the packing fails for some reason).

---

And this is what I use for TCZ extensions:

~/.config/xfe/scripts/tcz/un-squash
Code: [Select]
#!/bin/sh

for arg; do
xterm -e $HOME/.local/bin/tcz-unsquash $arg
done


~/.local/bin/tcz-unsquash
Code: [Select]
#!/bin/sh

if [ "${USER}" == "root" ]; then
echo "Don't run this as ROOT!"
popup "Don't run this as ROOT!" 2>/dev/null
exit 1
fi

if [ ! -f $1 ]; then
popup "Not a file or doesn't exist: $1" 2>/dev/null
exit 1
fi

#if [ ! -d /tmp/tcloop/squashfs-tools-* ]; then
# tce-load -i squashfs-tools-4.x.tcz
#fi
[ -f /usr/local/tce.installed/squashfs-tools-* ] || tce-load -i squashfs-tools-4.x.tcz

tcz_file=$1
tcz_path=${tcz_file/.tcz/}
unsquashfs -d $tcz_path $tcz_file


--

~/.config/xfe/scripts/tcz/squash
Code: [Select]
#!/bin/sh

for arg; do
xterm -e $HOME/.local/bin/tcz-squash $arg
done


~/.local/bin/tcz-squash
Code: [Select]
#!/bin/sh

if [ "${USER}" == "root" ]; then
echo "Don't run this as ROOT!"
popup "Don't run this as ROOT!" 2>/dev/null
exit 1
fi

if [ ! -d $1 ]; then
popup "Not a directory or doesn't exist: $1" 2>/dev/null
exit 1
fi

if [ ! -d /tmp/tcloop/squashfs-tools-* ]; then
tce-load -i squashfs-tools-4.x.tcz
fi

if [ -d $1/usr/local/tce.installed ]; then
sudo chown -R root.staff $1/usr/local/tce.installed
sudo chmod -R 775 $1/usr/local/tce.installed
fi

rm $1.tcz
mksquashfs $1 $1.tcz

Then I can copy it to either  /etc/sysconfig/tcedir/optional/upgrade/  or  /etc/sysconfig/tcedir/optional/  if it's an entirely new extension (Again, I'm doing this manually on purpose in case the packing fails for some reason).

--

Additionally, I use this script to mount a TCZ without 'installing' it, so I can just take a look at file permissions and umount it afterwards (no need for a un-mount script as Xfe already provides a feature for this).

~/.config/xfe/scripts/tcz/mount
Code: [Select]
#!/bin/sh

for arg; do
xterm -e $HOME/.local/bin/tcz-mount $arg
done


~/.local/bin/tcz-mount
Code: [Select]
#!/bin/sh

if [ ! -f "$1" ]; then
popup "Not a file or doesn't exist: $1" 2>/dev/null
exit 1
fi

MOUNTDIR="${1##*/}"
MOUNTPOINT="/tmp/squash/$MOUNTDIR"

mkdir -p "$MOUNTPOINT"
if [ ! -d "$MOUNTPOINT" ]; then
popup "Couldn't create mountpoint: $MOUNTPOINT" 2>/dev/null
exit 1
fi

sudo mount "$1" "$MOUNTPOINT"


--

Those scripts are of course provided as-is. I just hope they could be helpfull.
Any recommendations/suggestions/improvements or even additional scripts are very welcome.
Download a copy and keep it handy: Core book ;)