-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_macosx
69 lines (59 loc) · 1.88 KB
/
function_macosx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Open man page as PDF
manpdf()
{
man -t "${1}" | open -f -a /Applications/Preview.app/
}
# Show and select the given file(s) in the Finder
# Source: /~https://github.com/janmoesen/tilde/blob/348c90caf004b7185816e620f240fd2406e4eace/.bash/commands#L259-L299
show()
{
# Default to the current directory.
[ $# -eq 0 ] && set -- .;
# Build the array of paths for AppleScript.
local path paths=();
for path; do
# Make sure each path exists.
if ! [ -e "$path" ]; then
echo "show: $path: No such file or directory";
continue;
fi;
# Crappily re-implement "readlink -f" ("realpath") for Darwin.
# (The "cd ... > /dev/null" hides CDPATH noise.)
[ -d "$path" ] \
&& path="$(cd "$path" > /dev/null && pwd)" \
|| path="$(cd "$(dirname "$path")" > /dev/null && \
echo "$PWD/$(basename "$path")")";
# Use the "POSIX file" AppleScript syntax.
paths+=("POSIX file \"${path//\"/\"}\"");
done;
[ "${#paths[@]}" -eq 0 ] && return;
# Group all output to pipe through osacript.
{
echo 'tell application "Finder"';
echo -n 'select {'; # "reveal" would select only the last file.
for ((i = 0; i < ${#paths[@]}; i++)); do
echo -n "${paths[$i]}";
[ $i -lt $(($# - 1)) ] && echo -n ', '; # Ugly array.join()...
done;
echo '}';
echo 'activate';
echo 'end tell';
} | osascript;
}
bwana()
{
open -a "$HOME/Applications/Bwana.app" man://$1
}
function bci() {
readonly cask=${1:?"The cask name must be specified"}
brew update
brew install --cask $cask --no-quarantine
cd $MACBOOK_SETUP_DIR
rm ./Brewfile
brew bundle dump --all
git add .
git commit -m "Update Brewfile after installation of $cask"
git push origin master
cd -
return 1
}