3 ms·
Yes, shell functions are cool. I use them to augment standard commands too, e.g. make head(1) or tail(1) output more lines than usual, depending on the terminal
by jcynix 6y ago
Yes, shell functions are cool. I use them to augment standard commands too, e.g. make head(1) or tail(1) output more lines than usual, depending on the terminal's number of lines:
head () {
if [[ $# -eq 0 ]]
then
/usr/bin/head -$[(LINES-1)/2]
elif [[ -f "$1" ]]
then
case $# in
(1) /usr/bin/head -$[(LINES-1)/2] $* ;;
(2) /usr/bin/head -$[LINES*5/12] $* ;;
(3) /usr/bin/head -$[(LINES-1)/3] $* ;;
(*) /usr/bin/head $* ;;
esac
else
/usr/bin/head $*
fi
}