Check These Out
A common mistake in Bash is to write command-line where there's command a reading a file and whose result is redirected to that file.
It can be easily avoided because of :
1) warnings "-bash: file.txt: cannot overwrite existing file"
2) options (often "-i") that let the command directly modify the file
but I like to have that small function that does the trick by waiting for the first command to end before trying to write into the file.
Lots of things could probably done in a better way, if you know one...
Only under linux.
Requires Gvim compiled with "clientserver" functionality and
wmctrl command installed on system.
Instead of servername can be used the current edited file name.
Put it in a function and map it for get rid of "Press a key" after execution.
Run as root. Path may vary depending on laptop model and video card (this was tested on an Acer laptop with ATI HD3200 video).
$ cat /proc/acpi/video/VGA/LCD/brightness
to discover the possible values for your display.
Use flag "--" to stop switch parsing
!$ recalls the last argument of the previous command. This is very useful when you have to operate several operations on the same file for example.
This is a equivalent to the GNU ' readlink' tool, but it supports following all the links, even in different directories.
An interesting alternative is this one, that gets the path of the destination file
$ myreadlink() { [ ! -h "$1" ] && echo "$1" || (local link="$(expr "$(command ls -ld -- "$1")" : '.*-> \(.*\)$')"; cd $(dirname $1); myreadlink "$link" | sed "s|^\([^/].*\)\$|$(dirname $1)/\1|"); }
Yet another way to add a line at the top a of text file with the help of the tac command (reverse cat).
Converts any number of seconds into days, hours, minutes and seconds.
sec2dhms() {
declare -i SS="$1"
D=$(( SS / 86400 ))
H=$(( SS % 86400 / 3600 ))
M=$(( SS % 3600 / 60 ))
S=$(( SS % 60 ))
[ "$D" -gt 0 ] && echo -n "${D}:"
[ "$H" -gt 0 ] && printf "%02g:" "$H"
printf "%02g:%02g\n" "$M" "$S"
}
Quick write some notes to a file with cat. Ctrl+C when you have finish.