From 355d851507632d5a50e11e5d87c67e626ec1a4e9 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Tue, 21 Oct 2014 11:00:04 -0700 Subject: [PATCH] Emacs cocoa WIP. --- dotfiles/lib/cocoa-emacs.scpt | 17 +++++++++++++++++ dotfiles/lib/shellrc/colors.sh | 3 ++- resources/set-path.plist | 16 ++++++++++++++++ tasks/osx.py | 27 +++++++++++++++++++++------ tasks/util.py | 9 +++++++++ 5 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 dotfiles/lib/cocoa-emacs.scpt create mode 100644 resources/set-path.plist diff --git a/dotfiles/lib/cocoa-emacs.scpt b/dotfiles/lib/cocoa-emacs.scpt new file mode 100644 index 00000000..6d2a8ce0 --- /dev/null +++ b/dotfiles/lib/cocoa-emacs.scpt @@ -0,0 +1,17 @@ +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 \ No newline at end of file diff --git a/dotfiles/lib/shellrc/colors.sh b/dotfiles/lib/shellrc/colors.sh index 84b66662..2ad5537f 100644 --- a/dotfiles/lib/shellrc/colors.sh +++ b/dotfiles/lib/shellrc/colors.sh @@ -1,2 +1,3 @@ dircolors_file="$HOME/.dircolors" -test -r $dircolors_files && eval "$(dircolors $dircolors_file)" + +[ ! -z "$SHELL" ] && test -r $dircolors_files && eval "$(dircolors $dircolors_file)" diff --git a/resources/set-path.plist b/resources/set-path.plist new file mode 100644 index 00000000..5c7d02aa --- /dev/null +++ b/resources/set-path.plist @@ -0,0 +1,16 @@ + + + + + Label + set-path + ProgramArguments + + zsh + -c + 'source ~/.zshrc; launchctl setenv PATH $PATH' + + KeepAlive + + + \ No newline at end of file diff --git a/tasks/osx.py b/tasks/osx.py index b513ab90..19786e61 100644 --- a/tasks/osx.py +++ b/tasks/osx.py @@ -2,7 +2,7 @@ import os from invoke import ctask -from .util import RESOURCES_DIRECTORY, command_exists +from . import util @ctask(default=True) @@ -11,6 +11,7 @@ def all(ctx): get_brew(ctx) brew_install(ctx) brew_cask(ctx) + setup_cocoa_emacs(ctx) osx_config(ctx) @@ -33,11 +34,15 @@ SHOULD_INSTALL = ( MISC = ("file-formula", "less", "openssh --with-brewed-openssl", "perl518", "rsync", "svn", "unzip", "docker", "boot2docker", "pandoc", "mercurial") - CASKS = ('alfred', 'caffeine', 'flux', 'google-chrome', 'iterm2', 'spotify', 'vlc', 'virtualbox', 'xquartz') + + @ctask def osx_config(ctx): - ctx.run('source {0}; osx_config'.format(os.path.join(RESOURCES_DIRECTORY, 'osx.sh'))) + ctx.run('source {0}; osx_config'.format( + os.path.join(util.RESOURCES_DIRECTORY, 'osx.sh') + )) + @ctask def brew_cask(ctx): @@ -45,9 +50,10 @@ def brew_cask(ctx): for cask in CASKS: ctx.run('brew cask install {0}'.format(cask)) + @ctask def get_brew(ctx): - if not command_exists('brew'): + if not util.command_exists('brew'): ctx.run('ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"') @ctask @@ -55,9 +61,18 @@ def brew_install(ctx): for package_name in ESSENTIAL + BASICS + SHOULD_INSTALL + MISC: ctx.run('brew install {0}'.format(package_name)) + @ctask -def setup_emacs(ctx): - ctx.run('ln -s $(brew --prefix emacs) /Applications/emacs') +def setup_cocoa_emacs(ctx): + if not os.path.exists('/Applications/emacs'): + ctx.run('ln -s $(brew --prefix emacs) /Applications/emacs', hide=True) + launch_agent_dir = os.path.expanduser('~/Library/LaunchAgents/') + filename = 'set-path.plist' + 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) + )) @ctask diff --git a/tasks/util.py b/tasks/util.py index 67a82574..723fca6e 100644 --- a/tasks/util.py +++ b/tasks/util.py @@ -1,3 +1,4 @@ +import errno import os from invoke import run @@ -10,3 +11,11 @@ RESOURCES_DIRECTORY = os.path.join(REPO_DIRECTORY, 'resources') def command_exists(command, run=run): return run("hash {0}".format(command), warn=True, hide=True).exited == 0 + + +def ensure_path_exists(path): + try: + os.makedirs(path) + except OSError as exception: + if exception.errno != errno.EEXIST: + raise