Skip to content

Instantly share code, notes, and snippets.

@RobTrew
Last active April 5, 2021 15:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RobTrew/0af9040c4592053c35d6 to your computer and use it in GitHub Desktop.
Save RobTrew/0af9040c4592053c35d6 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
# 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