... | ... |
@@ -1,63 +1,99 @@ |
1 |
-alias showfiles='defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder' |
|
2 |
-alias hidefiles='defaults write com.apple.finder AppleShowAllFiles FALSE; killall Finder' |
|
1 |
+# ------------------------------------------------------------------------------ |
|
2 |
+# FILE: osx.plugin.zsh |
|
3 |
+# DESCRIPTION: oh-my-zsh plugin file. |
|
4 |
+# AUTHOR: Sorin Ionescu (sorin.ionescu@gmail.com) |
|
5 |
+# VERSION: 1.0.1 |
|
6 |
+# ------------------------------------------------------------------------------ |
|
3 | 7 |
|
4 |
-# Recursively delete .DS_Store files |
|
5 |
-alias rm-dsstore="find . -name '*.DS_Store' -type f -delete" |
|
6 |
- |
|
7 |
-function savepath() { |
|
8 |
- pwd > ~/.current_path~ |
|
9 |
-} |
|
10 | 8 |
|
11 | 9 |
function tab() { |
12 |
-savepath |
|
13 |
-osascript >/dev/null <<EOF |
|
14 |
-on do_submenu(app_name, menu_name, menu_item, submenu_item) |
|
15 |
- -- bring the target application to the front |
|
16 |
- tell application app_name |
|
17 |
- activate |
|
18 |
- end tell |
|
19 |
- tell application "System Events" |
|
20 |
- tell process app_name |
|
21 |
- tell menu bar 1 |
|
22 |
- tell menu bar item menu_name |
|
23 |
- tell menu menu_name |
|
24 |
- tell menu item menu_item |
|
25 |
- tell menu menu_item |
|
26 |
- click menu item submenu_item |
|
27 |
- end tell |
|
28 |
- end tell |
|
29 |
- end tell |
|
30 |
- end tell |
|
31 |
- end tell |
|
10 |
+ local command="cd \\\"$PWD\\\"" |
|
11 |
+ (( $# > 0 )) && command="${command}; $*" |
|
12 |
+ |
|
13 |
+ the_app=$( |
|
14 |
+ osascript 2>/dev/null <<EOF |
|
15 |
+ tell application "System Events" |
|
16 |
+ name of first item of (every process whose frontmost is true) |
|
32 | 17 |
end tell |
33 |
- end tell |
|
34 |
-end do_submenu |
|
18 |
+EOF |
|
19 |
+ ) |
|
35 | 20 |
|
36 |
-do_submenu("Terminal", "Shell", "New Tab", 1) |
|
21 |
+ [[ "$the_app" == 'Terminal' ]] && { |
|
22 |
+ osascript 2>/dev/null <<EOF |
|
23 |
+ tell application "System Events" |
|
24 |
+ tell process "Terminal" to keystroke "t" using command down |
|
25 |
+ tell application "Terminal" to do script "${command}" in front window |
|
26 |
+ end tell |
|
37 | 27 |
EOF |
38 |
-} |
|
28 |
+ } |
|
39 | 29 |
|
40 |
-function itab() { |
|
41 |
-savepath |
|
42 |
-osascript >/dev/null <<EOF |
|
43 |
-on do_submenu(app_name, menu_name, menu_item) |
|
44 |
- -- bring the target application to the front |
|
45 |
- tell application app_name |
|
46 |
- activate |
|
47 |
- end tell |
|
48 |
- tell application "System Events" |
|
49 |
- tell process app_name |
|
50 |
- tell menu bar 1 |
|
51 |
- tell menu bar item menu_name |
|
52 |
- tell menu menu_name |
|
53 |
- click menu item menu_item |
|
54 |
- end tell |
|
30 |
+ [[ "$the_app" == 'iTerm' ]] && { |
|
31 |
+ osascript 2>/dev/null <<EOF |
|
32 |
+ tell application "iTerm" |
|
33 |
+ set current_terminal to current terminal |
|
34 |
+ tell current_terminal |
|
35 |
+ launch session "Default Session" |
|
36 |
+ set current_session to current session |
|
37 |
+ tell current_session |
|
38 |
+ write text "${command}" |
|
55 | 39 |
end tell |
56 | 40 |
end tell |
57 | 41 |
end tell |
42 |
+EOF |
|
43 |
+ } |
|
44 |
+} |
|
45 |
+ |
|
46 |
+function pfd() { |
|
47 |
+ osascript 2>/dev/null <<EOF |
|
48 |
+ tell application "Finder" |
|
49 |
+ return POSIX path of (target of window 1 as alias) |
|
58 | 50 |
end tell |
59 |
-end do_submenu |
|
51 |
+EOF |
|
52 |
+} |
|
60 | 53 |
|
61 |
-do_submenu("iTerm", "Shell", "New Tab") |
|
54 |
+function pfs() { |
|
55 |
+ osascript 2>/dev/null <<EOF |
|
56 |
+ set output to "" |
|
57 |
+ tell application "Finder" to set the_selection to selection |
|
58 |
+ set item_count to count the_selection |
|
59 |
+ repeat with item_index from 1 to count the_selection |
|
60 |
+ if item_index is less than item_count then set the_delimiter to "\n" |
|
61 |
+ if item_index is item_count then set the_delimiter to "" |
|
62 |
+ set output to output & ((item item_index of the_selection as alias)'s POSIX path) & the_delimiter |
|
63 |
+ end repeat |
|
62 | 64 |
EOF |
63 | 65 |
} |
66 |
+ |
|
67 |
+function cdf() { |
|
68 |
+ cd "$(pfd)" |
|
69 |
+} |
|
70 |
+ |
|
71 |
+function pushdf() { |
|
72 |
+ pushd "$(pfd)" |
|
73 |
+} |
|
74 |
+ |
|
75 |
+function quick-look() { |
|
76 |
+ (( $# > 0 )) && qlmanage -p $* &>/dev/null & |
|
77 |
+} |
|
78 |
+ |
|
79 |
+function man-preview() { |
|
80 |
+ man -t "$@" | open -f -a Preview |
|
81 |
+} |
|
82 |
+ |
|
83 |
+function trash() { |
|
84 |
+ local trash_dir="${HOME}/.Trash" |
|
85 |
+ local temp_ifs=$IFS |
|
86 |
+ IFS=$'\n' |
|
87 |
+ for item in "$@"; do |
|
88 |
+ if [[ -e "$item" ]]; then |
|
89 |
+ item_name="$(basename $item)" |
|
90 |
+ if [[ -e "${trash_dir}/${item_name}" ]]; then |
|
91 |
+ mv -f "$item" "${trash_dir}/${item_name} $(date "+%H-%M-%S")" |
|
92 |
+ else |
|
93 |
+ mv -f "$item" "${trash_dir}/" |
|
94 |
+ fi |
|
95 |
+ fi |
|
96 |
+ done |
|
97 |
+ IFS=$temp_ifs |
|
98 |
+} |
|
99 |
+ |