You are not logged in.
I made one focused on monthly screens, that uses omploader and generates bbcode.
Offline
^cool script.
Thanks, man.
Offline
vik_k wrote:^cool script.
Thanks, man.
lol, that is cool. Nice work.
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
Gen2ly,
I love your pacbac and pacrest scripts. However, can you recommend how to alter pecrest to use bauerbill instead of yaourt??
AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64
Offline
Actually I haven't tried bauerbill ** hushes quietly so Xyne doesn't hear **. I'm not familiar with bauerbills' syntax but if it's the same as pacman/yaourt it's just requires a fix in two places: the one to check if bauerbill is installed an the other to actually download the source-code and build the packages. Here's a wild stab in the dark but it should be too much trouble to fix.
#!/bin/bash
# pacrest - Restore from list Official and Local packages
# Package list locations (official and local)
pkglsdir=/home/todd/.bin/root/backup
pkglsoff="$pkglsdir"/pkglist-off.txt
pkglsloc="$pkglsdir"/pkglist-loc.txt
# Local package cache location
locpkgcache=/var/cache/pacman-local/pkg
# Exclude packages
excldoff=()
excldloc=(kdemultimedia-kmix-oss-svn firefox-pgo-alpha-hg penumbra-collection worldofgoo)
# Use filename as program name
prog=${0##*/}
# Text color variables
if [ $(whoami) != "cron" ]; then
txtund=$(tput sgr 0 1) # Underline
txtcyn=$(tput setaf 6) # Cyan
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldblu=${txtbld}$(tput setaf 4) # blue
bldwht=${txtbld}$(tput setaf 7) # white
txtrst=$(tput sgr0) # Reset
info=${bldwht}*${txtrst} # Feedback
pass=${bldblu}*${txtrst}
warn=${bldred}*${txtrst}
fi
# Check that the package list folder exists
if [ ! -d "$pkglsdir" ]; then
echo "$warn Package list directory doesn't exist: ("$pkglsdir")"
echo "$info Exiting"
exit
fi
# Check that a package list exists
if [ ! -f "$pkglsoff" ] && [ ! -f "$pkglsloc" ]; then
echo "$warn No package lists exist:"
echo "$warn $pkglsoff and $pkglsoff"
echo "$info Exiting"
exit
fi
# Be sure yaourt is installed
if [[ ! -f /usr/bin/bauerbill ]]; then
echo
echo "$warn $prog requires ${txtund}}Bauerbill${txtrst} to be installed."
echo
exit
fi
# Restore Official or Local?
echo -n "Do you want to restore Official or Local packages? (${txtbld}o${txtrst}/${txtbld}l${txtrst}): "
read restore
# Restore Official
if [ $restore = "o" ]; then
# Download new package database?
echo -n "Upgrade package database? (${txtbld}y${txtrst}/${txtbld}n${txtrst}): "
read updbdown
if [ $updbdown = "y" ]; then
sudo pacman -Sy
fi
sudo pacman -S --needed $(cat "$pkglsoff")
fi
# Restore Local (AUR usually)
if [ $restore = "l" ]; then
bauerbill -S $(cat "$pkglsloc" | grep -vx "$(pacman -Qqm)")
fi
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
Gen2ly... and if I don't install bauerbill from aur but from his repo? Then I would remove or comment out
the last block of your script?
AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64
Offline
This is my first major script in bash, and I wrote it so that I wouldn't have to cd everytime to the file that I wanted to open. I could just run this script and it would find the file and run it in the specified program. It saves me a ton of time on the command line.
If there is more than one file with the same name it prints out all the files with there path names and lets you choose one.
#!/bin/sh
#Joshua Kneer
#This script finds the file specified by $1
#and runs it in an appropriate program
#######################################
#NOTE: This is my first ambitious shell script
#as such it is inevitably going to be ugly,
#inelegent, and otherwise offensive to more advanced programmers
#I apologize in advance, and would love to see corrections
########################################
#TO DO:
#1) get default programs working
#2) colorize output?
#default programs to use:
####THIS FEATURE DOES NOT WORK YET####
#TEXTEDITOR=/usr/bin/vim
#AUDIOPLAYER=/usr/bin/mocp
#############################################
#if the program has less than 1 argument exit
if [ $# -lt 1 ]; then
echo "\nspecify a file to open\n"
exit 1
fi
#############################################
#getting the file
FILE=`find ~/ -name "$1" -print` #assigning the file to open
if [ -z "$FILE" ]; then
echo no file found
exit 1
fi
##########################################################
#in case there is more than one file with the same name
#we print a list of all the files with that name and allow
#the user to pick the one that they would like to open
if [ `find ~/ -name "$1" -print | wc -l` -ne 1 ]; then
echo "There is more than one file with that name"
echo which would you like to open?
i=1 #a counting variable
#this loop prints out all the files
#matched with a number next to them
echo "$FILE" | while read name ; do
echo "$i) $name"
let i=$i+1
done
#this stores the file number from the list that they would
#like to open
num=1
read num
#picking file $num from the list of files
FILE=`echo "$FILE" | sed -n $num\p`
fi
########################################################
#printing out the file to open
echo "opening $FILE"
clear
########################################################################
#if there are two args, then opening the file with the specified program
if [ $# == 2 ]; then
$2 "$FILE"
exit 0
fi
########################################################################
########################################################################
#if the file is text, opening with TEXTEDITOR
if [ `file "$FILE" | sed '/text/ c\text'` == "text" ]; then
vim "$FILE"
exit 0
fi
########################################################################
########################################################################
#if the file is text, opening with mocp
if [ `file "$FILE" | sed -re '/[Aa]udio/ c\audio'` == "audio" ]; then
mocp -l "$FILE"
exit 0
fi
########################################################################
########################################################################
#if the file is a document open with open office
if [ `file "$FILE" | sed -re '/.*Document.*/ c\document'` == "document" ]; then
soffice -writer "$FILE"
exit 0
fi
xdg-open $FILE
the other script is not actually a script but a bash function I wrote and put into .bashrc. It finds the specified directory and cd's to it so you don't need to type the full pathname. This also saves me a ton of time
function fcd ()
{
local dir=`find ~/ -name "$1"`
if [ $# -lt 1 ]; then
echo -e "\nspecify a file to open\n"
return
fi
if [ -z "$dir" ]; then
echo "no file found"
return
fi
if [ `find ~/ -name "$1" | wc -l` -gt 1 ]; then
echo "There is more than one directory with that name"
echo "please choose a directory"
local i=1
echo "$dir" | while read name ; do
echo "$i) $name"
let i=$i+1
done
local num=1
read num
dir=`echo "$dir" | sed -n $num\p`
fi
cd "$dir"
return 0
}
Last edited by trashcat (2010-03-16 14:38:48)
Offline
For the first, make $FIND an array, that way you can be much more efficient in handling multiple results. You can test the length of the array rather than calling find twice. Replace the backticks with the $() format, it's more readable and easier to use.
For the second script, look at the CDPATH environment variable.
[git] | [AURpkgs] | [arch-games]
Offline
look at the CDPATH environment variable.
holywtfomgiluvu. I can throw out my jump function...
I suppose now I need actual relevant content to post now. Here's a home brewed xdg-open script for people who don't actually use xdg-open. Customize to your liking.
#!/bin/bash
#
# A command line utility that mimics xdg-open
# Requires Bash 4.0+
#
# Arg check
[[ $# -ne 1 ]] && { echo "Usage: ${0##*/} <file>" >&2; exit 1; }
# Declare an associative array to keep track of our file types.
# Index elements can be a full MIME type (e.g. image/png), just
# the major MIME type (e.g. image) or a file extension (png).
declare -A handler
# To keep things clean, general programs should be declared for
# groups of filetypes resulting in the same program being used
# when a major MIME type won't correctly identify all filetypes.
# openoffice.org documents are an example of this.
doc=soffice
handler[doc]=$doc
handler[xls]=$doc
handler[odb]=$doc
handler[ods]=$doc
handler[application/vnd.oasis.opendocument.text]=$doc
image=feh
handler[image]=$image
#handler[image/png]=$image
#handler[image/gif]=$image
#handler[image/jpeg]=$image
#handler[image/jpg]=$image
#handler[image/png]=$image
handler[application/pdf]=apvlv
video=mplayer
handler[video]=$video
#handler[mkv]=$video
#handler[mpg]=$video
#handler[wmv]=$video
#handler[avi]=$video
# Fallback handler (should be a text editor)
default=${EDITOR:-vi}
# Determine the MIME type via 'file' and assign it to an array
# mimetype[0] = major (e.g. image)
# mimetype[1] = minor (e.g. png)
mimetype=($(file -bi "$*" | sed -n 's|\([a-zA-Z\-\.]*\)/\([a-zA-Z\-\.]*\);.*|\1 \2|p'))
# Determine the extension as a fallback method
ext=${1//*.}
# Try to open by exact MIME type
if [[ -n ${handler[${mimetype[0]}/${mimetype[1]}]} ]]; then
${handler[${mimetype[0]}/${mimetype[1]}]} "$*"
# Try to open by major MIME type
elif [[ -n ${handler[${mimetype[0]}]} ]]; then
${handler[${mimetype[0]}]} "$*"
# Try to open by extension
elif [[ -n ${handler[$ext]} ]]; then
${handler[$ext]} "$*"
# Well, I'm out of ideas. Use the $default.
else
$default "$*"
fi
Last edited by falconindy (2010-03-16 19:20:45)
Offline
Use "file" to use mime-type based opening rather than using the extension. Integrating this with the "standard" mime-type defaults would be awesome too.
[git] | [AURpkgs] | [arch-games]
Offline
Use "file" to use mime-type based opening rather than using the extension. Integrating this with the "standard" mime-type defaults would be awesome too.
Good call. Q&D rewrite with mild amounts of testing. I'm still at work, so I expect that it will break at some point.
edit: updated original post to avoid confusion.
Last edited by falconindy (2010-03-16 17:58:55)
Offline
DEFAULT=${EDITOR:-vi} would be better
Plus you should add some way to distinguish between major and minor mime type in the array key.
[git] | [AURpkgs] | [arch-games]
Offline
DEFAULT=${EDITOR:-vi} would be better
Also a good idea. Done.
Plus you should add some way to distinguish between major and minor mime type in the array key.
I'm not sure I understand what you're getting at here, so correct me if/when I'm wrong on this. If someone wants to make an exception for a minor type, they should include the major type with the definition. How often would you come across two types, let's call them a/nnn and b/nnn which could both be opened by the same program? How often would you come across nnn existing for multiple major types?
Offline
Oh I see what's going on now. I misread a bit. Distinguish between the mime and extension. Perhaps key should be ".ext"?
[git] | [AURpkgs] | [arch-games]
Offline
i made an edit to /usr/bin/xdg-mime that some might find useful in light of the above posts:
645 if [ -n "$trader_result" ] ; then
646 echo $trader_result
647 exit_success
648 # pbrisbin 3/9/2010 + allow wildcards
649 else
650 IFS='/' read -r major minor <<< "$MIME"
651 DEBUG 2 "Checking $x/applications/defaults.list for wildcard mimetype"
652 trader_result=`grep -F "$major/*=" $x/applications/defaults.list 2> /dev/null | cut -d '=' -f 2 | cut -d ';' -f 1`
653 if [ -n "$trader_result" ] ; then
654 echo $trader_result
655 exit_success
656 fi
657 # pbrisbin 3/9/2010 -
658 fi
659 done
660 exit_success
661 }
it basically lets you do this:
cat .local/share/applications/defaults.list
[Default Applications]
text/html=chromium.desktop
text/*=custom_vim.desktop
application/pdf=epdfview.desktop
application/ogg=custom_playnow.desktop
video/*=mplayer.desktop
image/*=mirage.desktop
audio/x-wav=mplayer.desktop
audio/*=custom_playnow.desktop
any apps that use xdg-open will now use major/* entries if no major/minor match is found.
i emailed this to the authors of xdg-mime but i haven't gotten a response.
//github/
Offline
This has probably been done before but I made it anyway since I didn't see one. I'm always wanting to update my /etc/hosts file with the latest source from http://www.someonewhocares.org/hosts but also wanted to keep my own list to be merged with it (it will copy your current /etc/hosts if you don't have your own, as defined in $personalhosts). Anyway, whenever I want to add a domain to /etc/hosts I write it/them to the $personalhosts file and before I reboot or poweroff I run "adup -r" to refresh the current /etc/hosts with my own changes. Alternatively I run "adup -b" to fetch newest source and merge changes. So, this could be handy if you're always updating /etc/hosts, is where I'm getting at with this.
#!/bin/zsh
# Simple /etc/hosts updating script and merging with your own list.
personalhosts=/etc/hosts.mine
help() {
<< EOF
adup is a small script to update the /etc/hosts file.
usage: adup [OPTIONS]
OPTIONS:
-b|--build Build new /etc/hosts from latest source at:
http://someonewhocares.org/hosts/hosts
Also merging your own $personalhosts file.
-r|--refresh Only refresh /etc/hosts with changes made from
your $personalhosts file.
-h|--help Show this message and exit.
EOF
}
do_safe() {
[[ -f $personalhosts ]] || cp -f /etc/hosts $personalhosts
cp -f /etc/hosts /etc/hosts~
}
case $1 in
'-b'|'--build')
do_safe
curl -s http://someonewhocares.org/hosts/hosts|\
sed -e '1,/#<localhost>/c#<localhost>' -e '/# Acknowledgements/,$s/.*//;/^$/d' >! /etc/hosts
<$personalhosts>> /etc/hosts
;;
'-r'|'--refresh')
do_safe
<$personalhosts</etc/hosts~|awk ' !x[$0]--'>! /etc/hosts
;;
'-h'|'--help') help
;;
* ) print "Error: unrecognized option \"$1\". See --help."
;;
esac
I guess it will work if you put "#!/bin/bash" too but I didn't try. So, as you see when it merges the files it will remove duplicates as it does so. It will also remove all that jibber-jabber from the top of the website and the Acknowledgements at the bottom. Maybe the sed stuff could've been better but it seems to work. Of course it has to be ran as root unless (terribly) your /etc/hosts file is writable by $USER, but if you see an obvious safety issue let me know and I'll remove it.
Pretty simple and relatively handy if it's your kinda thing. I literally wrote it just now because I remembered it's been a long time since I updated the hosts file, so if it doesn't work let me know as well. I haven't read up on how to refresh /etc/hosts to be effective immediately (if it's possible). Certainly nothing to gawk at but it has the possibility of being expanded upon if you do more with /etc/hosts file than I do. So, blah. Onto bigger, unfinished stuff..
EDIT: Updated to use their text file instead of dumping from page. Uses curl now.
Last edited by milomouse (2010-03-17 14:20:59)
Offline
Nice idea. You might want to get http://www.someonewhocares.org/hosts/hosts though as that's a text file and means there's no web stuff left hanging about after the -dump. Of course, that now means you can get the file using something other than wget.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Wow. That hosts file makes Privoxy and NoScript look like child's play. Serious appreciation right here, thanks for the link
Offline
@skanky: Ah, how did I miss that. Thanks for pointing that out. It will definitely be better than dumping it from the page
Offline
I only spotted it because I didn't want to strip out the comments, etc., so the menu appeared at the top of the hosts file. So I thought, why isn't this a text file...
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
This script is an hg update hook that gets around the lack of fine-grained permissions in mercurial. This allows me to use hg on $HOME and /etc.
#!/bin/bash
repo="$(hg root)"
case "${repo}" in
"/etc")
cd "${repo}"
for file in $(hg manifest) ; do
perms=$(stat -c %a "${file}")
case "${file}" in
"shadow"|"gshadow")
if [[ "${perms}" == "644" ]] ; then
chmod -v 600 "${file}"
fi
;;
*)
if [[ "${perms}" == "700" ]] ; then
chmod -v 755 "${file}"
elif [[ "${perms}" == "600" ]] ; then
chmod -v 644 "${file}"
fi
;;
esac
done
;;
"/home/ataraxia")
cd "${repo}"
for file in $(hg manifest) ; do
perms=$(stat -c %a "${file}")
if [[ "${perms}" == "755" ]] ; then
chmod -v 700 "${file}"
elif [[ "${perms}" == "644" ]] ; then
chmod -v 600 "${file}"
fi
done
;;
*)
;;
esac
Offline
Something fun, a terminal screensaver based on pipes:
#!/bin/bash
declare -i f=75 s=13 r=2000 t=0 c=1 n=0 l=0
declare -ir w=$(tput cols) h=$(tput lines)
declare -i x=$((w/2)) y=$((h/2))
declare -ar v=( [00]="\x83" [01]="\x8f" [03]="\x93"
[10]="\x9b" [11]="\x81" [12]="\x93"
[21]="\x97" [22]="\x83" [23]="\x9b"
[30]="\x97" [32]="\x8f" [33]="\x81" )
OPTIND=1
while getopts "f:s:r:h" arg; do
case $arg in
f) ((f=($OPTARG>19 && $OPTARG<101)?$OPTARG:$f));;
s) ((s=($OPTARG>4 && $OPTARG<16 )?$OPTARG:$s));;
r) ((r=($OPTARG>0)?$OPTARG:$r));;
h) echo -e "Usage: pipes [OPTION]..."
echo -e "Animated pipes terminal screensaver.\n"
echo -e " -f [20-100]\tframerate (D=75)."
echo -e " -s [5-15]\tprobability of a straight fitting (D=13)."
echo -e " -r LIMIT\treset after x characters (D=2000)."
echo -e " -h\t\thelp (this screen).\n"
exit 0;;
esac
done
tput smcup
tput reset
tput civis
while ! read -t0.0$((1000/$f)) -n1; do
# New position:
(($l%2)) && ((x+=($l==1)?1:-1))
((!($l%2))) && ((y+=($l==2)?1:-1))
# Loop on edges (change color on loop):
((c=($x>$w || $x<0 || $y>$h || $y<0)?($RANDOM%7-1):$c))
((x=($x>$w)?0:(($x<0)?$w:$x)))
((y=($y>$h)?0:(($y<0)?$h:$y)))
# New random direction:
((n=$RANDOM%$s-1))
((n=($n>1||$n==0)?$l:$l+$n))
((n=($n<0)?3:$n%4))
# Print:
tput cup $y $x
echo -ne "\033[1;3${c}m\xe2\x94${v[$l$n]}"
(($t>$r)) && tput reset && tput civis && t=0 || ((t++))
l=$n
done
tput rmcup
Here's a shot of it working:
Offline
This script is useful in firefox, when viewing a flash video, the keyboard stops working.
In that case keyboard control is restored to firefox after clicking on some part of the webpage. This script does exactly that, and i have assigned a shortcut key to this.
So whenever i get stuck viewing a flash video and am too lazy to use the mouse, i just use this script and it does the job.
#!/bin/bash
# Get window id of firefox
WID=`xdotool search --title --name "Namoroka_-_Vimperator"`
# Set focus to firefox
xdotool windowfocus $WID
# Move cursor to the specified position
xdotool mousemove 996 720
# Send a mouse click (left click) to firefox
xdotool click 1
# Move cursor to top-middle of the screen
xdotool mousemove 909 10
Note: To be able to use this script, you will have to modify the title part to something that matches your firefox title and maybe even the coordinates part.
Oh yes since i use xdotool for this, all credit goes to the developer of xdotool for this.
Last edited by x33a (2010-03-21 02:17:01)
Offline
That's hilarious. Nice script. The windows pipes screensaver was pretty cool.
Thanks.
Offline