Skip to content

Instantly share code, notes, and snippets.

@mmisono
Created September 20, 2010 07:05
Show Gist options
  • Save mmisono/587520 to your computer and use it in GitHub Desktop.
Save mmisono/587520 to your computer and use it in GitHub Desktop.
function latest(){
local dir num
num=1
while getopts hn: OPT
do
case $OPT in
"n" ) num="$OPTARG"
shift 2 ;;
* ) echo "Usage: $0 [-n number] [dir]" 1>&2
return;;
esac
done
if [ $# = 0 ]; then
dir="`pwd`/"
else
dir="$1/"
shift 1
fi
for i in `ls -t ${dir}$1 | head -n $num`
do
echo ${dir}${i}
done
}
function _latest(){
_arguments -s : \
'l:file:_files'
}
compdef _latest latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment