You are not logged in.
Thanks steve___ - that does simplify it considerably
Offline
I wrote a tiny bash script for my dwm statusbar. It gives me the percent battery I have left in square brackets if charging or parentheses if discharging. If the computer is a desktop, it just displays "[|]".
Oh, and if there is less than 10% battery remaining it prints a big obnoxious message!
#!/bin/bash
acpi=$(LC_ALL=C acpi -b 2>/dev/null)
[ -z "$acpi" ] && echo "[|]" && exit
batt=${acpi#* * * }
batt=${batt%%, *}
batt=${batt%%%}
case $acpi in
*Discharging*)
if [ $batt -lt 10 ]; then
battwarning="!!!WARNING LOW BATTERY!!!"
fi
batt="($batt%)"
;;
*)
batt="[$batt%]"
;;
esac
echo "$battwarning$batt"
Offline
I have a local repo with some stuff from myself and some packages from the AUR (so can i update all my machines from this repo and dont have to package the AUR stuff multiple times). I wrote a script to auto-update that repo, when there are new pkg versions in the AUR. It has 200 lines so i will post a link: https://github.com/ushis/scripts/blob/m … local-repo
Offline
Well, what can I say, I do love rotating wallpapers :-)
So here's two scripts to change wallpapers randomly, using gnome
The first script is a loop that pick a random wallpaper from my wallpaper directory, and change it every 10 minutes
#!/bin/bash
while [[ 1 -eq 1 ]]
do
wallpapers=(/path/to/your/wallpaper/directory/*)
randnumber=$(echo $((RANDOM%${#wallpapers[@]}+0)))
gsettings set org.gnome.desktop.background picture-uri file:"${wallpapers["$randnumber"]}"
sleep 600
done
If you install the gnome-session package, you'lle be able to add the script to the list of the sartup applications with:
gnome-session-properties
Sometimes, it lands on a random wallpaper that I don't really like, so the script without the loop can be use to change to another random wallpaper on-the-fly
#!/bin/bash
wallpapers=(/path/to/your/wallpaper/directory/*)
randnumber=$(echo $((RANDOM%${#wallpapers[@]}+0)))
gsettings set org.gnome.desktop.background picture-uri file:"${wallpapers["$randnumber"]}"
I've made a desktop entry for this script, simply save it as instantwallaper.desktop (or whatevernameyouwant.desktop) in /usr/share/applications:
[Desktop Entry]
Name=Instant Random Wallpaper
Comment=Change Wallpaper
Exec=/path/to/the/script.sh
Terminal=true
Type=Application
Icon=instant.png
StartupNotify=true
And copy the icon you want (I've simply found one I like on Google) as /usr/share/icons/instant.png (or any name you want, as long as you keep it consistant with your Desktop Entry.
It will now appear on gnome-shell applications menu, and you'll be able to pin it to the dock
Voilà, one click instant wallpaper change!
Last edited by haiku (2012-02-18 13:29:43)
Hasta la Singularidad Siempre
Offline
Here is "mkvripper", it will rip all the tracks from a mkv while retaining the language information of each track (unless undefined).
#!/bin/bash
counter=0
movie="$(basename "$1" ".mkv")"
lang+=($(mkvinfo "$1" | awk '/Language/ { print $4 }'))
for track in $(mkvinfo "$1" | awk '/Codec ID/ { print $5 }'); do
case "$track" in
"V_MPEG2") format=m2v ;;
"V_MPEG4/ISO/AVC") format=h264 ;;
"V_MS/VFW/FOURCC") format=avi ;;
"A_MPEG/L3") format=mp3 ;;
"A_PCM/INT/LIT") format=wav ;;
"A_AC3") format=ac3 ;;
"A_AAC") format=aac ;;
"S_TEXT/UTF8") format=srt ;;
"S_TEXT/SSA") format=ssa ;;
"S_TEXT/ASS") format=ass ;;
*) : ;;
esac
mkv_tracks+=("$counter":"$movie"_"${lang["$counter"]}"."$format")
let counter++
done
mkvextract tracks "$1" "${mkv_tracks[@]}"
Thanks Kaustic, script updated!
Last edited by xr4y (2012-02-19 19:10:24)
Offline
There's no need to use grep and awk.
...
lang+=($(mkvinfo "$1" | awk '/Language/ { print $4 }'))
for track in $(mkvinfo "$1" | awk '/Codec ID/ { print $5 }'); do
...
[kaustiq][$][~]
mediainfo videos/alien.mkv | awk '/^Language/ {print $3}'
English
Last edited by Earnestly (2012-02-19 17:15:32)
Offline
Here is a little script, that puts date and time on the wallpaper and updates
each minute. It goes into .xinitrc . You will also need imagemagick, and feh
for this.
while true;
do
convert -background black \
-size 1280x800 -fill green -pointsize 72 \
-gravity center \
label:"$(date +'%d %B %Y')\n$(date +'%A')\n$(date +'%H:%M')" label.png\
&& feh --bg-scale label.png
sleep 1m
done &
Last edited by yasar11732 (2012-02-20 16:44:39)
Yo Dawg, I heard you likes patches, so I have created a patch for your patch, so you can patch your patches before you patch.
Offline
I made a script to optimize freedesktop.org comliant .desktop files within /usr/share/applications a few years back when I was much more of a newbie to Linux and python. It's not really a small script though, and it was written quite a long time ago.
You can get it on github: https://gist.github.com/1885413. I have just done a few updates to it for the first time in years to fix a bug I just found -- however it still requires Python 2.x. I have no interest in porting it to Python 3 myself. I can confirm it still works in Python 2.x.
The original thread I created for the script can also be found over at ubuntuforums.org. If you'd like to try using it, make sure you read through that thread to understand what is happening and how to use it. The versions linked in that thread are out of date, however. Use the one on github as this takes account for some changes I just made.
I have no honest idea if it's a bad idea to remove all of those unnecceassy locale entries -- but Iv'e never experienced any problems. Regardless I wouldn't want to be responsible for any damages, so I'd advise running it with backup enabled (or create a backup yourself...) backup is not enabled by default.. must use '-b' switch.). See --help for list of available switches.
sudo python2 appentry-optimize.py -b
Offline
This program plays all of the files in a directory, but it has one important difference from simply doing mplayer *foo, it will allow you to add files while the playlist is going. Why would this be useful? Well, some people (like me) want to watch a set of files that are being downloaded sequentially, and may not be in the actual directory, but don't want to manually play each file at a time.
Example usage: lazyplay.py seq <filetype> (e.g. avi or mkv) -mplayer_arg1 -mplayer_arg2 (e.g. -fs if you want the videos to play fullscreen)
Passing "rand" instead of "seq" will play the files in a random order instead of in sequence.
import subprocess as sp
from sys import argv
from glob import glob
from collections import deque
from random import shuffle
from functools import partial
FILE_TYPE = "*%s" % argv[2]
print FILE_TYPE
def new(cont, fs, played):
fs = [f for f in fs if f not in played]
cont(fs)
return fs
args = ["mplayer"]
args.extend(argv[3:])
print args
if argv[1] == "rand":
playlist = deque(glob(FILE_TYPE))
shuffle(playlist)
fileGet = partial(new, shuffle)
elif argv[1] == "seq":
playlist = deque(sorted(glob(FILE_TYPE)))
fileGet = partial(new, lambda x: x)
print "Playing: %s" % playlist
played = set(playlist)
while playlist:
print playlist
current = playlist.popleft()
cp = sp.Popen(args+[current])
cp.wait()
newfiles = fileGet(glob(FILE_TYPE), played)
playlist.extend(newfiles)
played.update(newfiles)
and a version written in MIT/GNU Scheme:
(load-option 'format)
(define (partial f x)
(lambda (y) (f x y)))
(define (flip f)
(lambda (y x) (f x y)))
(define (file-list) (directory-read (pwd)))
(define (files file-list)
(map
(partial (flip pathname-default-type) "") file-list))
(define (checksuffixes file-list)
(filter (lambda (x) (string=? "avi" (pathname-type x))) file-list))
(define (play-list)
(checksuffixes (files (file-list))))
(define played
(let* ((table (make-hash-table)))
(map (lambda (fname)
(hash-table/put! table fname #f)) (play-list))
table))
(define (update htable fnames)
(cond ((null? fnames) htable)
(else (map (lambda (fname)
(hash-table/put! htable fname #f)) fnames)
htable)))
(define (is-not-subset sett x)
(hash-table/get sett x #t))
(define (new-files sett files)
(let* ((check (partial is-not-subset sett)))
(filter check files)))
(define (play-file fnames)
(let* ((fname (car fnames)))
(run-shell-command (format #f "mplayer '~A.~A'" (pathname-name fname) (pathname-type fname)))))
(define (play fnames played)
(cond ((null? fnames) '())
(else (let* ((newfs (new-files played (play-list))))
(play-file fnames)
(play (append (cdr fnames) newfs) (update played newfs))))))
(play (play-list) played)
Last edited by Nisstyre56 (2012-03-01 23:04:40)
In Zen they say: If something is boring after two minutes, try it for four. If still boring, try it for eight, sixteen, thirty-two, and so on. Eventually one discovers that it's not boring at all but very interesting.
~ John Cage
Offline
Lossless quality screen recording, with what-u-hear and microphone streams in to separate files. Uses PulseAudio and ffmpeg. although it's pretty basic.
#! /bin/bash
function start()
{
# Pulse device indexs, use "pacmd list" to find them.
STEREO=0
MIC=1
parec -d $STEREO -r --file-format=flac > stereo.flac &
REC1=$!
parec -d $MIC -r --file-format=flac > mic.flac &
REC2=$!
ffmpeg -v quiet -s 1280x1024 -f x11grab -r 60 -i :0.0 \
-vcodec zlib -y desktop.mkv &
REC3=$!
echo "Recording, ^C to stop."
}
function end()
{
# 15 = SIGTERM
kill -s 15 $REC1
kill -s 15 $REC2
kill -s 15 $REC3
echo 1
exit 0
}
trap "enc" TERM
start
while [[ 1 ]]; do
true # "do nothing, successfully"
done
Offline
Wordcount script for latex files - I use it by a vim key binding. I wouldn't be surprised if such a tool was in one of those vim-latex packages, but I prefer to write my own utilities so I know exactly how they work and how to change them when needed.
#!/bin/bash
# TexCount: applies `wc` to latex files as follows:
# 1) all output of the processed latex file
# 2) "Body" text, after removing references
#
# Dependencies: pdflatex, pdftotext
# Get the base filename
BASE="${1%.tex}"
# Convert the tex to text via pdf
clear; echo -e "\033[36mProcessing Word Count ...\033[0m"
tex2pdf "$1" > /dev/null 2>&1
pdftotext -raw "$BASE".pdf
# Print a table of `wc` data
clear; echo
echo -e "\033[33;4mReferences\tLines\tWords\tCharacters\033[0m"
echo -en "with: \t"; wc "$BASE".txt | sed 's/ *\([0-9]*\) *\([0-9]*\) *\([0-9]*\).*/\1\t\2\t\3/'
sed -i '/^References/,$ d' "$BASE".txt
echo -en "without:\t"; wc "$BASE".txt | sed 's/ *\([0-9]*\) *\([0-9]*\) *\([0-9]*\).*/\1\t\2\t\3/'
echo
# cleanup
rm "$BASE".txt
Last edited by Trilby (2012-02-29 18:13:55)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Online
Simple CD/DVD Burning Script. It supports burning from directories, burning from iso files, and wiping RW disks. It also supports handling iso files via your file manager or arguments.
Extra features: sha256sum generation for directory burning; disk space check before even attempting to call wodim/genisofs (RWs might not be handled correctly by this; I assumed that they are equal to their +/-R counterparts in terms of free space)
"Features" it lacks: Support for non-iso disk images and multisession burning.
The main script has 360 lines, so I've uploaded it instead: http://dbox.darksniper.tk/Scripts/burn
For ease of editing, all of the functions are in alphabetical order (aside from the main functions that only call the other functions)
In addition to cdrkit and dvd+rw-tools, it requires that you have setup your optical drive symlinks (Though the wiki page for this escapes me at the moment)
The .desktop file for ISO handling looks like this (and goes in ~/.local/share/applications)
NOTE: This is for XFCE's terminal, you'll probably have to change the exec line if you use a different terminal.
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Exec=terminal -x burn isoburnmgr %f
Name=IsoBurn
NoDisplay=true
Icon=brasero
Then, to associate it, add it to your mimeapps.list in the same directory:
[Default Applications]
application/x-cd-image=burn.desktop
[Added Associations]
application/x-cd-image=burn.desktop;
And... I'll post this one too.
This is a simple way of performing routine maintenance on BTRFS volumes in one clean command.
It mounts your pool (if it's not already mounted), Scrubs it, Defragments it (And optionally compresses any files that are not compressed already), then balances it. If your BTRFS volume wasn't mounted before running the script, it'll unmount it when it's done.
It should have plenty of sanity checks to prevent you from doing anything nasty to your volume. If any operation fails along the way, the script immediately quits to avoid (further) damaging your filesystem.
I STRONGLY recommend against using this while you're actually going to be using the computer if your root is in the BTRFS pool. Both balancing and scrubbing create a huge loss in performance while they run.
#!/bin/bash
## Settings
# UUID of BTRFS Partition. It is assumed that you have this in your fstab with your fancy mount options.
btfsuuid=87ee144a-1e76-4b8f-9521-62057616e0d0
# Mountpoint of BTRFS Partition. It should match the one in your fstab.
mountpoint=/var/lib/linux-root
# Compression to be applied while defragmenting (MUST be in this syntax: -c<insertcompressionhere>)
# Comment out if you don't use compression
compress="-clzo"
# Sanity checks
if [[ $(id -u) -ne 0 ]]; then
echo "This script must be run as root. Exiting..."
exit 1
elif ! blkid | grep -q "$btrfsuuid"; then
echo "You've set an invalid UUID. Exiting..."
exit 1
elif [ ! -d "${mountpoint}" ]; then
echo "Your mountpoint doesn't exist. Exiting..."
exit 1
elif [ -n "$compress" ]; then
if [ "$compress" != "-clzo" -a "$compress" != "-czlib" ]; then
echo "Invalid compression type. Exiting..."
exit 1
fi
fi
# Mount the BTRFS Root (If it's not mounted already)
if ! grep -q "$mountpoint" /proc/self/mounts; then
echo -n "Mounting BTRFS Root... "
if mount UUID=${btrfsuuid} "$mountpoint"; then
echo "Done!"
echo
unmount=yes
else
echo "Failed!"
exit 1
fi
fi
# Check for mount once more. If it's not mounted by now, nasty things might happen.
if ! grep -q "$mountpoint" /proc/self/mounts; then
echo "ERROR. Your BTRFS volume is still not mounted!"
echo "Exiting to prevent potential filesystem damage..."
exit 1
fi
## BTRFS operations begin here.
# Scrub the Root
echo -n "Scrubbing BTRFS... "
if btrfs scrub start -B "$mountpoint" &> /tmp/scrubout; then
echo "Done!"
cat /tmp/scrubout
rm /tmp/scrubout
echo
else
echo "Failed!"
cat /tmp/scrubout
rm /tmp/scrubout
exit 1
fi
# Defragment the Root
echo -n "Defragmenting and Compressing BTRFS... "
btrfs filesystem defragment ${compress} "$mountpoint"
# The source code is weird! It ADDS 20 to its return code for defragging, so 20 = 0?
if [ "$?" = 20 ]; then
echo "Done!"
echo
else
echo "Failed!"
exit 1
fi
# Balance the Root
echo -n "Balancing BTRFS... "
if btrfs filesystem balance "$mountpoint"; then
echo "Done!"
echo
else
echo "Failed!"
exit 1
fi
# Unmount the Root (If it wasn't mounted at the beginning)
if [ "$unmount" = "yes" ]; then
echo -n "Unmounting BTRFS Root... "
if umount "$mountpoint"; then
echo "Done!"
echo
else
echo "Failed!"
echo "Your volume is probably still mounted! You may have to unmount it manually."
fi
fi
echo "Your BTRFS Volume Has Been Optimized."
Last edited by DarkSniper (2012-03-01 16:28:22)
Failure is not an option... It comes bundled with Windows.
Offline
#!/bin/bash while [[ 1 -eq 1 ]] do ...
Any special reason to write this "[[ 1 -eq 1 ]]"?
while :; do
: = true
Offline
What's wrong with simply while true; do?
: may be less typing sure (3 extra keys takes long?) but true is way more legible (understandable) code.
..or am I missing something?
Last edited by Earnestly (2012-03-03 00:08:00)
Offline
: may be less typing sure (3 extra keys takes long?)
I have to press and hold Shift and press ';' to get ':' so that's even less advantageous ;P
Offline
I've recently started using Wyrd and Remind for calendar/scheduling.
I wrote the following to be called from ~/.Xmobarrc to display upcoming appointment(s) in my xmobar (XMonad taskbar).
It should only need slight adjustment to work with similar taskbars/dzen/conky
#!/bin/bash
remind -b1 -n ~/.wyrd | sort | awk '
BEGIN {
displayed=0;
}
/^'`date +%Y\\\/%m\\\/%d`'/ {
hour=$2;
min=$2
sub(/:.*/,"",hour);
sub(/.*:/,"",min);
if ( hour > '`date +%H`') {
sub(/[^ ]* /,"");
if (displayed == 0) {
printf "|| <fc=#118822>"$0"</fc> |";
} else if (displayed == 1) {
printf " "$0" |";
}
displayed++;
} else if ( hour == '`date +%H`' && min + 10 > '`date +%M`') {
sub(/[^ ]* /,"");
if (displayed == 0) {
printf "|| <fc=#118822>"$0"</fc> |";
} else if (displayed == 1) {
printf " "$0" |";
}
displayed++;
}
}
END {
if (displayed > 0)
print "|";
}
'
This displays the next 2 appointments for the day with the first highlighted in a brighter green while the second is displayed in the default color (dark green for my xmobar). If there is only one remaining appointment, it is displayed in the brighter green. If there are no appointments left in the day, nothing is displayed.
~/.wyrd would have to be changed to your .rem file or folder.
Past appointments remain listed for 10 minutes after their start time (So I know when I'm late!)
Last edited by Trilby (2012-03-05 20:48:04)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Online
I have something a little more, ahem, rudimentary as my reminder system
#!/bin/bash
# email reminder notes using at(1)...
read -p "Time of message? [HH:MM] " time
read -p "Date of message? [dd.mm.yy] " date
read -p "Message body? " message
at "$time" "$date" << EOF
echo "$message" | mailx -s "REMINDER" jasonwryan@gmail.com
EOF
Offline
Scan files for binary dependencies and translate to packages:
#!/bin/bash
#
# resolve ELF library deps to pacman packages
#
declare -r lddregex=$'(.+) => (.+) \(0x[a-fA-F0-9]+\)'
resolve_bin() {
declare -A depmap
declare -a linkage
local lddout=$(ldd "$1" 2>/dev/null) || return
# leverage the linker to do lib resolution
while read -r line; do
[[ $line =~ $lddregex ]] || continue
depmap["${BASH_REMATCH[1]}"]=${BASH_REMATCH[2]}
done <<< "$lddout"
objdump -p "$1" 2>/dev/null | while read section soname; do
[[ $section == NEEDED && ${depmap[$soname]} ]] && printf '%s\n' "${depmap[$soname]}"
done | pacman -Qqo - 2>/dev/null
}
for bin; do
resolve_bin "$bin"
done | sort -u
Use it to scan a $pkgdir:
$ find pkg/ -type f -executable -exec elf2pkgs {} +
Scan an installed package:
$ pacman -Qql <pkg> | xargs -d$'\n' elf2pkgs
Offline
because I can't stand, when I'm browsing with chromium or firefox, to see how my processor is fully used while I'm just watching something on you tube (I believe the flash player is the reason for this), I thought playing with the CPU governors might help
#!/bin/sh
while true
do
var1=$(ps -e | grep chromium | tail -1 | sed 's/[0-9]//g;s/?//g;s/://g;s/ //g')
var2=$(ps -e | grep firefox | tail -1 | sed 's/[0-9]//g;s/?//g;s/://g;s/ //g')
if [ $var1 == "chromium" ] || [ $var2 == "firefox" ];
then
det1=$(lsmod | awk '/powersave/ {print $3}');
if [ $det1 != 1 ];
then
for i in 0 1; do cpufreq-set -c $i -g powersave; done;
fi
else
det2=$(lsmod | awk '/conservative/ {print $3}');
if [ $det2 != 1 ];
then
for i in 0 1; do cpufreq-set -c $i -g conservative; done;
fi
fi
sleep 5
done
Frankly 1000 MHz ( in my case this is the processor speed while having the powersave governor) for web browsing and using flash player is more than enough.
I've first installed Arch in March
Offline
a 4 day weather forecast script:
it splits the output into 4 quadrants.
If utilizes the conkyForecast,py script and is required.
#!/bin/bash
# 4 Day Weather forecast script for Boardman, OH
# Written by Habitual/JJ
# 11.01.2010 12:10:07
# Clear the screen
tput clear
# Tomorrow...(Top-Left Quadrant of output)
tput cup 0 0
echo "Forecast for" `date --date="1 day" | awk '{print $1 ", " $2 " "$3 " "$6}'`
tput cup 1 0
echo "----------------------------"
tput cup 2 0
echo "Low: " `/usr/bin/conkyForecast.py --location=USOH1096 -d LT --imperial --startday 1`
tput cup 3 0
echo "High:" `/usr/bin/conkyForecast.py --location=USOH1096 -d HT --imperial --startday 1`
tput cup 4 0
echo "Humidity:" `/usr/bin/conkyForecast.py --location=USOH1096 -d HM --imperial --startday 1`
tput cup 5 0
echo `/usr/bin/conkyForecast.py --location=USOH1096 -d CT --startday 1`
tput cup 6 0
tput bold; tput setaf 1;
echo "Precipitation:" `/usr/bin/conkyForecast.py --location=USOH1096 -d PC --startday 1`
tput sgr0
# Tomorrow +1...(Top-Right Quadrant of output)
tput cup 0 40
echo "Forecast for" `date --date="2 day" | awk '{print $1 ", " $2 " "$3 " "$6}'`
tput cup 1 40
echo "----------------------------"
tput cup 2 40
echo "Low: " `/usr/bin/conkyForecast.py --location=USOH1096 -d LT --imperial --startday 2`
tput cup 3 40
echo "High:" `/usr/bin/conkyForecast.py --location=USOH1096 -d HT --imperial --startday 2`
tput cup 4 40
echo "Humidity:" `/usr/bin/conkyForecast.py --location=USOH1096 -d HM --imperial --startday 2`
tput cup 5 40
echo `/usr/bin/conkyForecast.py --location=USOH1096 -d CT --startday 2`
tput cup 6 40
tput bold; tput setaf 1;
echo "Precipitation:" `/usr/bin/conkyForecast.py --location=USOH1096 -d PC --startday 2`
tput sgr0
# Tomorrow +2...(Bottom-Left Quadrant of output)
tput cup 9 0
echo "Forecast for" `date --date="3 day" | awk '{print $1 ", " $2 " "$3 " "$6}'`
tput cup 10 0
echo "----------------------------"
tput cup 11 0
echo "Low: " `/usr/bin/conkyForecast.py --location=USOH1096 -d LT --imperial --startday 3`
tput cup 12 0
echo "High:" `/usr/bin/conkyForecast.py --location=USOH1096 -d HT --imperial --startday 3`
tput cup 13 0
echo "Humidity:" `/usr/bin/conkyForecast.py --location=USOH1096 -d HM --imperial --startday 3`
tput cup 14 0
echo `/usr/bin/conkyForecast.py --location=USOH1096 -d CT --startday 3`
tput cup 15 0
tput bold; tput setaf 1;
echo "Precipitation:" `/usr/bin/conkyForecast.py --location=USOH1096 -d PC --startday 3`
tput sgr0
# Tomorrow +3...(Bottom-Right Quadrant of output)
tput cup 9 40
echo "Forecast for" `date --date="4 day" | awk '{print $1 ", " $2 " "$3 " "$6}'`
tput cup 10 40
echo "----------------------------"
tput cup 11 40
echo "Low: " `/usr/bin/conkyForecast.py --location=USOH1096 -d LT --imperial --startday 4`
tput cup 12 40
echo "High:" `/usr/bin/conkyForecast.py --location=USOH1096 -d HT --imperial --startday 4`
tput cup 13 40
echo "Humidiy:" `/usr/bin/conkyForecast.py --location=USOH1096 -d HM --imperial --startday 4`
tput cup 14 40
echo `/usr/bin/conkyForecast.py --location=USOH1096 -d CT --startday 4`
tput cup 15 40
tput bold; tput setaf 1;
echo "Precipitation:" `/usr/bin/conkyForecast.py --location=USOH1096 -d PC --startday 4`
tput sgr0
tput cup 17 0
#EOF
Offline
I was bored and then I came with _this_ script, well, 3. "Powered" by pieppiep, it's just for th- tweetin', I can get notifies, see my replies, and send tweets from a small _form_.
Maybe i just did something that was already _invented_; but it was worth, my bash _skills_ are better than a year ago as I can see, haha
There are 3 scripts: twitter.sh replies.sh and post.sh
1. twitter.sh
#!/usr/bin/env bash
#script para cargar el timeline siempre y cuando haya nuevos tweets.
twitteruser="asdf_chan"
log=$(date +%s)
echo $log.replies.twitter >/tmp/.twitter.plog
fetch_tweets () {
pieppiep fetch ${fetchnum} >>/tmp/${log}.twitter
}
fetch_replies () {
tail -${tailnum} /tmp/${log}.twitter | grep "@${twitteruser}"
}
loop_tweets () {
while [ 1 ]; do
fetchnum="$(pieppiep nr)"
((tailnum=${fetchnum}*3))
if [ ${fetchnum} -le 1 ]; then
break;
else
#echo $tailnum #debug
fetch_tweets && tail -${tailnum} /tmp/${log}.twitter
replies="$(fetch_replies grep "@${twitteruser}" | wc -l)"
if (("${replies}" > "0")); then
echo -e "\n$(date +%d/%m/%Y\ %H:%M:%S)\n $(fetch_replies)" >>/tmp/$log.replies.twitter
notify-send "${replies} replies @${twitteruser}";
fi
break;
fi
done
}
while [ 1 ]; do
loop_tweets
sleep 20;
done
#not yet
#get rid of _logs_ & stuff
#rm /tmp/*twitter*
2.replies.sh
#!/usr/bin/env bash
#Mostrar las respuestas de forma -simpática-
check_replies () {
if [ -f /tmp/$(cat /tmp/.twitter.plog) ]; then
break;
fi
}
while [ 1 ]; do
check_replies
done
clear && echo -e "\nREPLIES: @asdf_chan" && tail -f /tmp/$(cat /tmp/.twitter.plog)
3.post.sh
#!/usr/bin/env bash
#script para enviar tweets de una forma -simpática-
input_tweet () {
clear;
echo -e "\nEscribe algo al mundo:\n"
read -e "input"
}
while [ 1 ]; do
input_tweet
echo -e "\nEnviando a twitter..."
pieppiep post "${input}"
done
Sorry for the few comments~ Maybe later, I'd add something
In "twitter.sh", (it'd better timeline.sh, right?), at the very end you can read a #get rid of _logs_ and stuff# Inded, I'm not sure yet how to delete theese files when I break the loop with CTRL+C, later gonna google this "problem", haha~
pic related (dvtm <3):
Offline
I got tired of typing emacs -nw and C-x b <Enter>. I only use Emacs for occasional prose anyway.
#!/usr/bin/env bash
if isatty; then
emacs -nw --no-splash $*
else
emacs
fi
isatty.c
#include <unistd.h>
int main(int argc, char *argv[])
{
return !isatty(0);
}
Offline
if isatty; then
<snip>
isatty.c
#include <unistd.h> int main(int argc, char *argv[]) { return !isatty(0); }
Instead of that you can use test -t 0 which does the same thing.
Edit: Or [[ -t 0 ]] I suppose...
Last edited by fsckd (2012-03-15 21:47:33)
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
A function to load vim and use sudo if the file is not writeable by the current user.
v () {
if [ -w "${@: -1}" ]
then
vim $@
else
sudo vim $@
fi
}
So use it by typing
v /path/to/file
Last edited by graph (2012-03-15 21:57:19)
Offline
Or (within Vim)
:w !sudo tee %
Offline