I had an interesting issue today: how to deal with the environment variable PAGER?
Here’s the big picture: not all distributions use the same default pager. You have on one side the more fans (Debian) and on the other side the less ones (Suse). I’m not taking into account the geeks who use something else (probably well tweaked).
Imagine now you want to display to the user your EULA in an installation script. How should you display it? Using more by default? Or PAGER? The second solution seems intuitive to me. After all, if I use a special, personal pager, I would be totally frustrated to have to deal with more when reading the EULA.
However, think about the beginner Suse user, who doesn’t know much about less. Reaching EOF, less will stop scrolling, if neither -e nor -E are specified. You need to type q to exit. The beginner would have no idea what to do to exit less.
The solution I came up with is to either use more if no pager is specified, and use PAGER otherwise. In the latter case, if is it less, -E is appended at the command line, with the regular flags the user might have specified in PAGER.
The solution works well. If no pager is specified or less is, the behavior will be to exit the pager when EOF is reached and the script can continue (“Do you accept…”). If a special, tweaked, pager is specified, it is very likely that the user specified it, so he know how to use it. And he won’t be frustrated when reading the text.
I was working the other day on Dateslider, a fancy Javascript library to create sliding date pickers (see the demo here).
After having refactored 300 lines of Javascript and added two classes, I realized it was time to backup my work! Unfortunately, I have no access to the initial repository. I could have simply zipped it and sent it to an external hard drive but I wanted to keep an history of my changes. I could have created a personal repository but sending files to the upstream team would be painful with all the .svn/ subdirectories…
I finally decided to go with rsync and emulate a repository.
#!/bin/sh
# svn.sh
# Directory to backup
DIRECTORYTOBACKUP=${1%/} # Remove trailing slash
# The name of the backup machine
# Don't even try to hack this CNAME, it doesn't exist.
BACKUPSERVER=backups.mouraf.org
# Auto-generated directory containing modified files
INCREMENTALDIR=`date +%m_%d_%y-%H_%M_%S`
OPTS="--progress --force --ignore-errors --delete --backup --backup-dir=/BAK/$DIRECTORYTOBACKUP/$INCREMENTALDIR -a --compress"
rsync $OPTS $DIRECTORYTOBACKUP backups@$BACKUPSERVER:/BAK/$DIRECTORYTOBACKUP/current
Note: refer to the rsync man page for details about available options. Have a look to “delete-excluded” and “exclude-from” which are especially helpful to avoid transferring Virtual Machines ram disks for instance…
With the command ./svn.sh dateslider, you end up backuping the entire directory dateslider to /BAK/dateslider/ on $BACKUPSERVER (you don’t have to send it to another server, you may simply backup it to an external drive for example). The current up-to-date version is in the current directory.
Each time you modify a file and fire up the script, another directory is created ($INCREMENTALDIR) with the old version of the modified file and the new version is updated in current.
I have aliased this script to commit on my machine. Once in a while, I run it. Hence I always have a current copy of my data and all the diff I may need. Not as powerful as a real repository, but helpful and secure for small and/or temporary projects.
As Julien pointed out, the Debian Administration website has some nice articles about “Commands you might have missed”. I came across this article ab
out watch, which repeatedly run a command.
watch 't=`ls -la | wc -l`;perl -e "print \"[\",\"x\"x($t),\".\"x(18-$t),\"]\n\";"'
which outputs something like:
Every 2.0s:
[xxxxxxxxxxxxx.....]
Each x represents a file which has already been transferred. In this example, I can see quickly that 5 files still need to be transferred.
By the way, this snippet to draw bars is quite handy. Here is what I use to get visually the space remaining on a drive:
server ~% t=`df -h | grep hdr42 | awk '{print $3/$2*50}'`;perl -e "print \"[\",\"x\"x($t),\".\"x(50-$t),\"]\n\";"
[xxxxxxxxxxxxxxxxxxxxxx................]
cated a binary file), use
reset
I would suggest to add
alias cls='reset' in your .bashrc to avoid auto-completing on reboot...Quick fix for the backspace key if it doesn’t work properly when SSHing to your linux box.
First, under
Terminal - Preferences - Advancedset
Delete sends Ctrl-HThis should allow the delete key to work in your screen session.
Then, in your linux box, fix the delete binding in your vimrc:
set t_kb=ctrl-vBACKSPACE
fixdel




