You are not logged in.
Pages: 1
Hi. Here are a collection of practical utilities that I made mostly in sh script.
I don't have much time to write this up, so here is the README file:
Silly utilities, by Mike Ledger.
Put them in your $PATH to use them properly.
Dependencies:
- GNU coreutils
- X (for flashing, panic and trip) although some other display method that
SDL supports would work fine too.
- SDL
- SDL_gfx
- optipng
- dash
- ompload
- zsh
alarm {in|at} [time] {h|m|s}: an alarm clock.
Example usage:
alarm in 3 s
Sets the alarm to ring in 3 seconds.
alarm in 6 h
Sets the alarm to ring in 6 hours.
alarm at 06:00:00
Sets the alarm for 6 AM. The times it accepts are in 24 hour format.
finder [string]: finds strings in files/folders/names.
foornt [file]: checks if a file is open.
lidwatch: a daemon to turn the screen on/off depending on whether the lid is
open or closed.
magicalshot: used by magicshot. Don't run this manually.
magicshot: screenshot utility. It will take a screenshot, optimise the png of
it, get a description of the screenshot, upload it to ompldr.org using ompload
and then save the description, link and filename to a file for later usage.
prepend [string]: prepend a string to a file.
rpath [file:///blahblah]: remove the file:// from the argument
shrs {suspend|shutdown|halt|reboot|restart|hibernate}: shutdown, hibernate,
reboot and suspend without being root.
toggle [process]: "toggles" the running of a process.
Example usage:
toggle xcompmgr -c -t-5 -l-5 -r4.2 -o.65
If xcompmgr is running, toggle will kill it. If not, it will run it
(arguments are preserved)
xarchive: use this for xarchiver + firefox. Firefox gives applications file:///
URIs and xarchiver and other applications don't know what to do with that.
Offline
I don't like backticks - $() is more sexy.
Why not use pgrep & pkill for toggle? Not sure if you want exactly this, but:
#!/bin/bash
if ! pgrep $1 >/dev/null; then
$@
else
pkill $1
fi
In alarm you do
if [ -z "`ps -A | grep flashing`" ]; then
...
I think pgrep would do OK here too.
rpath
rpath=$(echo "$@" | sed 's%file://%%')
1. Instead of escaping forward slashes, use another separator, like '%'.
2. Unless you use 's/foo/bar/g', sed removes only the first occurrence in the line, so no need for '^foo'.
Last edited by karol (2011-08-14 21:42:28)
Offline
Why not use pgrep & pkill for toggle? Not sure if you want exactly this, but:
#!/bin/bash if ! pgrep $1 >/dev/null; then $@ else pkill $1 fi
In alarm you do
if [ -z "`ps -A | grep flashing`" ]; then ...
I Think pgrep would do OK here too.
Updated to use pgrep.
Offline
https://github.com/mikeplus64/silly-uti … ter/foornt is awful:
[karol@black ~]$ lsof | grep t1
bash 2234 karol 254r REG 8,4 63 401559 /home/karol/test/foo0/t1~ (deleted)
bash 2240 karol 254r REG 8,4 63 401560 /home/karol/test/foo0/t1~ (deleted)
bash 2244 karol 254r REG 8,4 63 401560 /home/karol/test/foo0/t1~ (deleted)
The file is not open, I'm not editing t1.
You can use 'grep -q' to make things easier:
if lsof | grep -q $1; then
echo "$1 is open"
else
echo "$1 is not open"
fi
https://github.com/mikeplus64/silly-uti … r/lidwatch
You can use 'grep -q' and
while sleep 1; do
...
done
https://github.com/mikeplus64/silly-uti … er/prepend
Print warning when $FILE doesn't exist
if [ -f "$FILE" ]; then
echo "$STRING`cat "$FILE"`" > "$FILE"
else
echo "$FILE doesn't exist"
fi
Last edited by karol (2011-08-14 22:46:23)
Offline
Thanks karol, I committed some changes.
There is a bug with alarm that if you do
$ alarm in 15 s
Started: 16:39:49
Panicing at: 16:40:4
Current time: ^C:39:54
(the "timer" will never reach "16:40:4", so I ^C'd out)
If the seconds target is under 10, it'll not have a 0 in front of it, even though with minutes and hours it works.
Any ideas on how to fix that?
Offline
pgrep and pkill interpret the argument as extended regular expression, so your current implementation of toggle might not work as intended.
Assuming the toggle argument should be the _exact_ process name, you should use pgrep/kill "^$1$" instead.
$ ps -U root -u root u | grep udev
root 389 0.0 0.0 10860 1452 ? Ss 08:34 0:00 udevd --daemon
root 1932 0.0 0.0 10856 1112 ? S 08:38 0:00 udevd --daemon
root 1933 0.0 0.0 10856 1204 ? S 08:38 0:00 udevd --daemon
$ pgrep udev
389
1932
1933
$ pgrep ^udev$
$ pgrep ^udevd$
389
1932
1933
Offline
@xduugu
Or
-f The pattern is normally only matched against the process name. When -f is set,
the full command line is used.
Offline
I don't get it. How is it related to the potential problem that the argument is a pattern and not a simple string?
Offline
I don't get it. How is it related to the potential problem that the argument is a pattern and not a simple string?
You suggested OP might want the _exact_ process name; 'pgrep -f' works in the opposite fashion: https://bbs.archlinux.org/viewtopic.php?id=124355 so you can filter based on arguments
[karol@black ~]$ pgrep nolisten
[karol@black ~]$ pgrep -f nolisten
788
Sorry, I should have written "Or use 'pgrep -f' to do the opposite, to expand the search".
Last edited by karol (2011-08-15 09:55:47)
Offline
Pages: 1