-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.-lwill 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.