I got this bash script over at Jeff Channell's Blog. To get it fully functional you'll need both mednafen and zenity installed, to do so in Ubuntu derivatives open up a terminal and enter:
[sourcecode language="bash"]
user@com$ sudo apt-get install mednafen zenity
[/sourcecode]
Then Jeff's script, I suggest assigning this as a .bashrc alias like `nes` or the like.
[sourcecode language="bash"]
#!/bin/bash
# NES Rom Browser
# Jeff Channell, 5.07.2006
medgui_conf=~/.medgui
function medgui_start ()
{
touch $medgui_conf
zenity --question --title="Default Rom Directory?" --text="Press OK to select a default rom folder, or hit Cancel to always use your Home directory."
case $? in
0)
ROMPATH=`zenity --file-selection --directory --title="Select Default ROM Directory"`
;;
*)
ROMPATH=~/
;;
esac
echo "ROMPATH=$ROMPATH" >> $medgui_conf
}
if [ -e "$medgui_conf" ]
then
ROMPATH=`sed -n '/^ROMPATH=/p' $medgui_conf | sed -e 's/^ROMPATH=//'`
else
zenity --question --text="No config file found. Would you like to create one?"
case $? in
0)
echo "Creating file"
medgui_start
;;
1)
echo "Error: Cannot find default config!"
exit 2
;;
esac
fi
cd $ROMPATH
SELECTEDROM=`zenity --file-selection --title="Select An NES Rom File..."`
case $? in
0)
if [ -e "$SELECTEDROM" ]
then
file "$SELECTEDROM" | grep NES
case $? in
0)
mednafen -nes.no8lim 1 -nes.stretch 1 -nes.xres 1024 -nes.yres 768 "$SELECTEDROM"
;;
*)
zenity --error --text="The selected file does not appear to be an NES rom file!"
exit 1
;;
esac
else
zenity --error --text="Error: File Does Not Exist!"
exit 1
fi
;;
1)
echo "No rom selected. Exiting...";;
-1)
echo "No rom selected. Exiting...";;
esac
[/sourcecode]
Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts
Saturday, December 15, 2012
Saturday, December 8, 2012
Refactored Bash Recursive Shredir Function
Beware if you use this, it overwrites the data 34 times before annihilating it.

[sourcecode language="bash"]
alias shred="sudo shred -vxuz -n33"
function shredir() {
if [ -f "$1" ]
then
echo "Usage shredir <dir>"
else
if [ -z "$1" ]
then
for file in ./*
do
if [ -d $file ]
then
prevdir=$file;
cd $file;
shredir
cd "../";
rmdir $prevdir;
else
shred $file
fi
done
else
initdir=$1
for file in $1
do
if [ -d $file ]
then
prevdir=$file;
cd $file;
shredir
cd "../";
else
shred $file
fi
if [ -d $prevdir ]
then
rmdir $prevdir
fi
done
rmdir $initdir || >/dev/null
fi
fi
}
[/sourcecode]
[sourcecode language="bash"]
alias shred="sudo shred -vxuz -n33"
function shredir() {
if [ -f "$1" ]
then
echo "Usage shredir <dir>"
else
if [ -z "$1" ]
then
for file in ./*
do
if [ -d $file ]
then
prevdir=$file;
cd $file;
shredir
cd "../";
rmdir $prevdir;
else
shred $file
fi
done
else
initdir=$1
for file in $1
do
if [ -d $file ]
then
prevdir=$file;
cd $file;
shredir
cd "../";
else
shred $file
fi
if [ -d $prevdir ]
then
rmdir $prevdir
fi
done
rmdir $initdir || >/dev/null
fi
fi
}
[/sourcecode]
Tuesday, November 27, 2012
.bashrc Tweaks
If you're anything like the average *nix user you most likely find yourself in a terminal quite often. Myself being no different love extending my .bashrc file to add some time and headache saving aliases and functions; here's some of my favs.
These are especially handy when used in conjunction with other bash tools like sed and awk
[sourcecode language="bash"]
alias ll="ls -l --group-directories-first"
alias ls='ls -hF --color'
alias la='ls -Al'
alias lx='ls -lXB'
alias lk='ls -lSr'
alias lc='ls -ltcr'
alias lu='ls -ltur'
alias lt='ls -ltr'
alias lm='ls -al |more'
alias lr='ls -lR'
[/sourcecode]
This is extremely handy if you're either anal retentive about trash files or paranoid o_0 The first alias passes some flags to shred that cause it to annihilate a single file. The function I wrote below it recursively does the same with a whole directory, very fun to watch in a terminal.
[sourcecode language="bash"]
alias shred="sudo shred -vxuz -n33"
function shredd() {
if [ -z "$1" ]
then
for file in ./*
do
if [ -d $file ]
then
prevdir=$file
cd $file
shredd
cd "../"
rmdir $prevdir
else
shred $file
fi
done
else
initdir=$1
paramflag="true"
for file in $1
do
if [ -d $file ]
then
prevdir=$file
cd $file
shredd
cd "../"
rmdir $prevdir
else
shred $file
fi
done
fi
rmdir $initdir
}
[/sourcecode]
The unzip alias is for all those people tired of remembering which flags tar needs for a tar.gz or bz2 archives, yes I'm lazy. cleanpics wipes all exif meta data from jpg files, great for pics off your phone you want to sanitize.
[sourcecode language="bash"]
alias unzip='atool -x'
alias cleanpics='exiftool -all= *.jpg; rm *.jpg_original;'
[/sourcecode]
Some of these may not work until you install the proper packages but that's as easy as a sudo apt-get install shred. Have fun.
ls Aliases
These are especially handy when used in conjunction with other bash tools like sed and awk
[sourcecode language="bash"]
alias ll="ls -l --group-directories-first"
alias ls='ls -hF --color'
alias la='ls -Al'
alias lx='ls -lXB'
alias lk='ls -lSr'
alias lc='ls -ltcr'
alias lu='ls -ltur'
alias lt='ls -ltr'
alias lm='ls -al |more'
alias lr='ls -lR'
[/sourcecode]
The Shred Bomb
This is extremely handy if you're either anal retentive about trash files or paranoid o_0 The first alias passes some flags to shred that cause it to annihilate a single file. The function I wrote below it recursively does the same with a whole directory, very fun to watch in a terminal.
[sourcecode language="bash"]
alias shred="sudo shred -vxuz -n33"
function shredd() {
if [ -z "$1" ]
then
for file in ./*
do
if [ -d $file ]
then
prevdir=$file
cd $file
shredd
cd "../"
rmdir $prevdir
else
shred $file
fi
done
else
initdir=$1
paramflag="true"
for file in $1
do
if [ -d $file ]
then
prevdir=$file
cd $file
shredd
cd "../"
rmdir $prevdir
else
shred $file
fi
done
fi
rmdir $initdir
}
[/sourcecode]
Miscellaneous
The unzip alias is for all those people tired of remembering which flags tar needs for a tar.gz or bz2 archives, yes I'm lazy. cleanpics wipes all exif meta data from jpg files, great for pics off your phone you want to sanitize.
[sourcecode language="bash"]
alias unzip='atool -x'
alias cleanpics='exiftool -all= *.jpg; rm *.jpg_original;'
[/sourcecode]
Some of these may not work until you install the proper packages but that's as easy as a sudo apt-get install shred. Have fun.
Subscribe to:
Posts (Atom)