-
-
Save TheMetaphysicalCrook/ce5b38e29edc3ba1c33d82eb9d3e564e to your computer and use it in GitHub Desktop.
Bash command `lf` - like ls but selects glob-matched files in an OS X Finder window
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
# An lf command in my ~/.bash_profile | |
# like a simple ls, but selects the glob-matched files in the Finder | |
# `lf *.txt` to Finder-select all *.txt files in the working directory | |
# `lf *.[^t]?? to Finder-select all files with a 3-char extension which doesn't start with t | |
lf() { | |
local IFS=":"; local f=$@; local seln=""; fldr="$(pwd)" | |
for l in ${f[@]}; do | |
if [[ ! -d $l ]]; then | |
seln=$seln"file \"$l\", " | |
fi | |
done | |
local lst="{${seln:0:${#seln}-2}}" | |
osascript <<AS_END | |
tell application "Finder" | |
set str to POSIX path of (insertion location as string) | |
if "$fldr/" is not str then do shell script ("open -a Finder ./") | |
activate | |
tell front Finder window to select $lst | |
end tell | |
return "" | |
AS_END | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment