Skip to content

Instantly share code, notes, and snippets.

@Idloj
Created July 24, 2017 06:50
Show Gist options
  • Select an option

  • Save Idloj/a87aba5e3bd2cd3d7685d29533b23744 to your computer and use it in GitHub Desktop.

Select an option

Save Idloj/a87aba5e3bd2cd3d7685d29533b23744 to your computer and use it in GitHub Desktop.
Open files when you don't know their full name (or just want to save time)
#!/bin/bash -e
LOOP=false
BG=false
while true; do
case $1 in
-l|--loop) LOOP=true; shift ;;
-b|--background) BG=true; shift ;;
*) break
esac
done
function invoke {
$1 $2 &
$BG || wait
}
if [[ 1 == `locate -icl 2 "$2"` ]]; then
FILE=`locate -i "$2"`
invoke $1 "$FILE"
else
PS3="Choose which file to use: "
FILES=`locate -i "$2"`
IFS="
"
select file in $FILES; do
invoke $1 "$file"
$LOOP || break
done
fi
@Idloj
Copy link
Author

Idloj commented Jul 24, 2017

Typical usage: try vlc 'buck bunny'. If you have only one file matching, it'll be opened. If multiple files are found, you'll get a menu to choose the file from.

-l will let you choose another file to open when you finish with the current one. If you use -b, you can open the next file, while the current one is still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment