]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/osx/osx.plugin.zsh
add xbindkeysrc
[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.0.1
6 # ------------------------------------------------------------------------------
7
8
9 function tab() {
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)
17 end tell
18 EOF
19 )
20
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
27 EOF
28 }
29
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}"
39 end tell
40 end tell
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)
50 end tell
51 EOF
52 }
53
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
64 EOF
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