]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/osx/osx.plugin.zsh
Squashed commit of the following + cleanup afterwards:
[dotfiles.git] / zsh / plugins / osx / osx.plugin.zsh
1 # ------------------------------------------------------------------------------
2 # FILE: osx.plugin.zsh
3 # DESCRIPTION: oh-my-zsh plugin file.
4 # AUTHOR: Sorin Ionescu (sorin.ionescu@gmail.com)
5 # VERSION: 1.1.0
6 # ------------------------------------------------------------------------------
7
8 function tab() {
9 local command="cd \\\"$PWD\\\""
10 (( $# > 0 )) && command="${command}; $*"
11
12 the_app=$(
13 osascript 2>/dev/null <<EOF
14 tell application "System Events"
15 name of first item of (every process whose frontmost is true)
16 end tell
17 EOF
18 )
19
20 [[ "$the_app" == 'Terminal' ]] && {
21 osascript 2>/dev/null <<EOF
22 tell application "System Events"
23 tell process "Terminal" to keystroke "t" using command down
24 tell application "Terminal" to do script "${command}" in front window
25 end tell
26 EOF
27 }
28
29 [[ "$the_app" == 'iTerm' ]] && {
30 osascript 2>/dev/null <<EOF
31 tell application "iTerm"
32 set current_terminal to current terminal
33 tell current_terminal
34 launch session "Default Session"
35 set current_session to current session
36 tell current_session
37 write text "${command}; clear;"
38 end tell
39 end tell
40 end tell
41 EOF
42 }
43 }
44
45 function vsplit_tab() {
46 local command="cd \\\"$PWD\\\""
47 (( $# > 0 )) && command="${command}; $*"
48
49 the_app=$(
50 osascript 2>/dev/null <<EOF
51 tell application "System Events"
52 name of first item of (every process whose frontmost is true)
53 end tell
54 EOF
55 )
56
57 [[ "$the_app" == 'iTerm' ]] && {
58 osascript 2>/dev/null <<EOF
59 tell application "iTerm" to activate
60
61 tell application "System Events"
62 tell process "iTerm"
63 tell menu item "Split Vertically With Current Profile" of menu "Shell" of menu bar item "Shell" of menu bar 1
64 click
65 end tell
66 end tell
67 keystroke "${command}; clear;"
68 keystroke return
69 end tell
70 EOF
71 }
72 }
73
74 function split_tab() {
75 local command="cd \\\"$PWD\\\""
76 (( $# > 0 )) && command="${command}; $*"
77
78 the_app=$(
79 osascript 2>/dev/null <<EOF
80 tell application "System Events"
81 name of first item of (every process whose frontmost is true)
82 end tell
83 EOF
84 )
85
86 [[ "$the_app" == 'iTerm' ]] && {
87 osascript 2>/dev/null <<EOF
88 tell application "iTerm" to activate
89
90 tell application "System Events"
91 tell process "iTerm"
92 tell menu item "Split Horizontally With Current Profile" of menu "Shell" of menu bar item "Shell" of menu bar 1
93 click
94 end tell
95 end tell
96 keystroke "${command}; clear;"
97 keystroke return
98 end tell
99 EOF
100 }
101 }
102
103 function pfd() {
104 osascript 2>/dev/null <<EOF
105 tell application "Finder"
106 return POSIX path of (target of window 1 as alias)
107 end tell
108 EOF
109 }
110
111 function pfs() {
112 osascript 2>/dev/null <<EOF
113 set output to ""
114 tell application "Finder" to set the_selection to selection
115 set item_count to count the_selection
116 repeat with item_index from 1 to count the_selection
117 if item_index is less than item_count then set the_delimiter to "\n"
118 if item_index is item_count then set the_delimiter to ""
119 set output to output & ((item item_index of the_selection as alias)'s POSIX path) & the_delimiter
120 end repeat
121 EOF
122 }
123
124 function cdf() {
125 cd "$(pfd)"
126 }
127
128 function pushdf() {
129 pushd "$(pfd)"
130 }
131
132 function quick-look() {
133 (( $# > 0 )) && qlmanage -p $* &>/dev/null &
134 }
135
136 function man-preview() {
137 man -t "$@" | open -f -a Preview
138 }
139
140 function trash() {
141 local trash_dir="${HOME}/.Trash"
142 local temp_ifs=$IFS
143 IFS=$'\n'
144 for item in "$@"; do
145 if [[ -e "$item" ]]; then
146 item_name="$(basename $item)"
147 if [[ -e "${trash_dir}/${item_name}" ]]; then
148 mv -f "$item" "${trash_dir}/${item_name} $(date "+%H-%M-%S")"
149 else
150 mv -f "$item" "${trash_dir}/"
151 fi
152 fi
153 done
154 IFS=$temp_ifs
155 }
156