Skip to content

Instantly share code, notes, and snippets.

@cberzan
Last active August 14, 2017 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cberzan/f4a7a32cae69ba5380fd to your computer and use it in GitHub Desktop.
Save cberzan/f4a7a32cae69ba5380fd to your computer and use it in GitHub Desktop.
utils for handling recently downloaded files
# Utils for handling files in ~/Downloads:
DOWNLOADS_DIR="$HOME/Downloads"
function lsdl() {
ls --color -1 -t "$DOWNLOADS_DIR" |head |nl
}
function cpdl() {
if [ "a$1" == 'a-h' ] || [ "a$1" == 'a--help' ]; then
echo "Usage examples:"
echo " cpdl # copy most recent download into pwd"
echo " cpdl 3 # copy 3rd most recent download into pwd"
echo " cpdl 3 foo # copy 3rd most recent download into foo"
return 0
fi
# Using "${parameter:-default}" construct.
index=${1:-1}
dest=${2:-.}
filename=$(ls -1 -t ~/Downloads/ |sed -n "$index p")
echo "$filename"
src="$DOWNLOADS_DIR/$filename"
cp "$src" "$dest"
}
function mvdl() {
if [ "a$1" == 'a-h' ] || [ "a$1" == 'a--help' ]; then
echo "Usage examples:"
echo " mvdl # move most recent download into pwd"
echo " mvdl 3 # move 3rd most recent download into pwd"
echo " mvdl 3 foo # move 3rd most recent download into foo"
return 0
fi
# Using "${parameter:-default}" construct.
index=${1:-1}
dest=${2:-.}
filename=$(ls -1 -t ~/Downloads/ |sed -n "$index p")
echo "$filename"
src="$DOWNLOADS_DIR/$filename"
mv "$src" "$dest"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment