emacs cocoa stuff, set-path launch agent, as_user function.

This commit is contained in:
Ivan Malison 2014-10-21 15:20:43 -07:00
parent 355d851507
commit 4d707d59e3
8 changed files with 48 additions and 32 deletions

@ -1 +1 @@
Subproject commit ad458bced3a0cd204671c8e88c3f0f1e445eaf33
Subproject commit 3a01d4be1d0c953cd1c4f293e8d0b32b543a2131

View File

@ -1,17 +0,0 @@
tell application "Terminal"
try
-- we look for <= 2 because Emacs --daemon seems to always have an entry in visibile-frame-list even if there isn't
set frameVisible to do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -e '(<= 2 (length (visible-frame-list)))'"
if frameVisible is not "t" then
-- there is a not a visible frame, launch one
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n"
end if
on error
-- daemon is not running, start the daemon and open a frame
do shell script "/Applications/Emacs.app/Contents/MacOS/Emacs --daemon"
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n"
end try
end tell
-- bring the visible frame to the front
tell application "Emacs" to activate

View File

@ -9,6 +9,7 @@ function add_to_back_of_path {
add_to_back_of_path "$HOME/.local/lib/python2.6/site-packages"
hash brew 2>/dev/null && add_to_front_of_path "$(brew --prefix coreutils)/libexec/gnubin"
add_to_front_of_path "/usr/local/bin"
hash brew 2>/dev/null && add_to_front_of_path "$(brew --prefix emacs)/libexec/gnubin"
for filename in ~/.lib/shellrc/*; do
source $filename

View File

@ -1,5 +1,6 @@
alias emacs="emacsclient -t"
alias xemacs="\emacs --daemon > /dev/null 2&> /dev/null; emacsclient -c &"
alias emacs="emacsclient -c -n"
alias temacs="emacsclient -t"
alias cemacs="emacsclient -c -n"
alias tmux="tmux -2"
alias reload_tmux_conf="tmux source-file .tmux.conf"
alias tmux_cb_to_remote_cb='tmux saveb - | linux_nc_paste_to_remote_clipboard'

View File

@ -4,7 +4,7 @@ elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
# Make emacs the default editor.
export EDITOR="emacsclient"
export EDITOR="emacsclient -cn"
export ALTERNATE_EDITOR=""
export VISUAL="emacsclient"

View File

@ -265,3 +265,31 @@ EOF
function dirty_talk() {
while true; do talk_dirty_to_me | tee >(cat) | say; done
}
function as_user {
local user="$1"
local user_pid=$(ps -axj | awk "/^$user / {print \$2;exit}")
local command="sudo /bin/launchctl bsexec $user_pid sudo -u '$user' $2"
echo "Running:"
echo "$command"
eval $command
}
function as_current_user {
as_user "$(whoami)" "$*"
}
function reload_user_agent {
as_current_user /bin/launchctl unload "$1"
as_current_user /bin/launchctl load "$1"
}
function reload_root_agent {
as_user 'root' "/bin/launchctl unload '$1'"
as_user 'root' "/bin/launchctl load '$1'"
}
function ec {
emacsclient -n $1 > /dev/null
}

View File

@ -3,14 +3,14 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>set-path</string>
<string>com.example.hello</string>
<key>ProgramArguments</key>
<array>
<string>zsh</string>
<string>-c</string>
<string>'source ~/.zshrc; launchctl setenv PATH $PATH'</string>
<string>source ~/.zshrc && echo password | sudo -Sv && as_current_user /bin/launchctl setenv PATH $PATH</string>
</array>
<key>KeepAlive</key>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

View File

@ -64,15 +64,18 @@ def brew_install(ctx):
@ctask
def setup_cocoa_emacs(ctx):
if not os.path.exists('/Applications/emacs'):
ctx.run('ln -s $(brew --prefix emacs) /Applications/emacs', hide=True)
if not os.path.exists('/Applications/Emacs.app'):
ctx.run('ln -s $(brew --prefix emacs)/Emacs.app /Applications/Emacs.app', hide=True)
launch_agent_dir = os.path.expanduser('~/Library/LaunchAgents/')
filename = 'set-path.plist'
source = os.path.join(util.RESOURCES_DIRECTORY, filename)
destination = os.path.join(launch_agent_dir, filename)
if os.path.exists(source) and not os.path.exists(destination):
util.ensure_path_exists(launch_agent_dir)
ctx.run('cp {0} {1}'.format(
os.path.join(util.RESOURCES_DIRECTORY, filename),
os.path.join(launch_agent_dir, filename)
))
ctx.run('ln -s {0} {1}'.format(source, destination))
@ctask