Emacs server can sort of open files from finder.... this is hard though. Also emacs_open command.

This commit is contained in:
Ivan Malison 2014-11-18 02:50:59 -08:00
parent 9f57705921
commit 510f32b5d6
45 changed files with 509 additions and 141 deletions

View File

@ -1,128 +1,128 @@
{ {
"after-scripts": ["brew linkapps"], "after-scripts": ["brew linkapps"],
"casks": [ "casks": [
"alfred", "alfred",
"atom", "atom",
"caffeine", "caffeine",
"dropbox", "dropbox",
"firefox", "firefox",
"flash", "flash",
"flux", "flux",
"google-chrome", "google-chrome",
"google-hangouts", "google-hangouts",
"heroku-toolbelt", "heroku-toolbelt",
"iterm2", "iterm2",
"java", "java",
"karabiner", "karabiner",
"macpass", "macpass",
"osxfuse", "osxfuse",
"seil", "seil",
"slate", "slate",
"spotify", "spotify",
"sublime-text", "sublime-text",
"synergy", "synergy",
"transmission", "transmission",
"virtualbox", "virtualbox",
"vlc", "vlc",
"xquartz" "xquartz"
], ],
"formulas": [ "formulas": [
"ack", "ack",
"ag", "ag",
"ant", "ant",
"autoconf", "autoconf",
"automake", "automake",
"bash", "bash",
"binutils", "binutils",
"brew-cask", "brew-cask",
"cabal-install", "cabal-install",
"cmake", "cmake",
"coreutils", "coreutils",
"ctags", "ctags",
"daemonize", "daemonize",
"diffutils", "diffutils",
"docker", "docker",
"ed", "ed",
"emacs --cocoa --srgb", "emacs --cocoa --srgb",
"file-formula", "file-formula",
"findutils", "findutils",
"fontconfig", "fontconfig",
"fontforge", "fontforge",
"freetype", "freetype",
"gawk", "gawk",
"gdbm", "gdbm",
"gettext", "gettext",
"ghc", "ghc",
"gist", "gist",
"git", "git",
"giter8", "giter8",
"glib", "glib",
"globals", "globals",
"gnutls", "gnutls",
"go", "go",
"gobject-introspection", "gobject-introspection",
"grep", "grep",
"gtk+3", "gtk+3",
"gupnp", "gupnp",
"gzip", "gzip",
"heroku-toolbelt", "heroku-toolbelt",
"htop-osx", "htop-osx",
"hub", "hub",
"icu4c", "icu4c",
"intltool", "intltool",
"jpeg", "jpeg",
"less", "less",
"libevent", "libevent",
"libffi", "libffi",
"libidn", "libidn",
"libpng", "libpng",
"libsoup", "libsoup",
"libtasn1", "libtasn1",
"libtiff", "libtiff",
"libtool", "libtool",
"lzip", "lzip",
"make", "make",
"mercurial", "mercurial",
"netcat", "netcat",
"nettle", "nettle",
"ngrep", "ngrep",
"nmap", "nmap",
"node", "node",
"openssl", "openssl",
"ossp-uuid", "ossp-uuid",
"pandoc", "pandoc",
"pango", "pango",
"pcre", "pcre",
"pixman", "pixman",
"pkg-config", "pkg-config",
"pstree", "pstree",
"pv", "pv",
"pypy", "pypy",
"python", "python",
"python3", "python3",
"rbenv", "rbenv",
"readline", "readline",
"reattach-to-user-namespace", "reattach-to-user-namespace",
"rsync", "rsync",
"sbt", "sbt",
"scala", "scala",
"sdl", "sdl",
"sdl_image", "sdl_image",
"sdl_mixer", "sdl_mixer",
"sdl_ttf", "sdl_ttf",
"sleuthkit", "sleuthkit",
"sqlite", "sqlite",
"subversion", "subversion",
"tig", "tig",
"tmux", "tmux",
"unzip", "unzip",
"vim", "vim",
"watch", "watch",
"wdiff", "wdiff",
"webp", "webp",
"weechat", "weechat",
"wget", "wget",
"xz", "xz",
"zsh" "zsh"
] ]
} }

@ -1 +1 @@
Subproject commit 93424eed9ab89ee80f081a6e165304b5fe6e25f9 Subproject commit d9155dc397e5f0e3234e883c4245f9fb1f0ece04

View File

@ -1,4 +1,4 @@
alias emacs='_emacs -c -n' alias emacs='_emacs -c -n '
is_osx && alias emacs='cocoa_emacs' is_osx && alias emacs='cocoa_emacs'
alias terminal_emacs='_emacs -t' alias terminal_emacs='_emacs -t'
alias ec='_emacs -n ' alias ec='_emacs -n '
@ -10,16 +10,21 @@ function cocoa_emacs {
} }
function _emacs { function _emacs {
local server_name="$GLOBAL_EMACS" local server_name="$(_emacs_server_file)"
[ -z $GLOBAL_EMACS ] && server_name="$(_current_dot_directory)" if ! emacs_daemon_exists "$server_name"; then
if ! _emacs_daemon_exists "$server_name"; then
echo "Starting emacs with server name '$server_name'" echo "Starting emacs with server name '$server_name'"
command emacs --daemon="$server_name" command emacs --daemon="$server_name"
fi fi
emacsclient $* --server-file=$server_name emacsclient "$@" --server-file=$server_name
} }
function _emacs_daemon_exists { function _emacs_server_file {
local server_name="$GLOBAL_EMACS"
[ -z $GLOBAL_EMACS ] && server_name="$(_current_dot_directory)"
echo $server_name
}
function emacs_daemon_exists {
! test -z "$(ps aux | grep -v grep | grep -i "emacs.*--daemon=.*$1$")" ! test -z "$(ps aux | grep -v grep | grep -i "emacs.*--daemon=.*$1$")"
} }
@ -32,6 +37,32 @@ function _current_dot_directory {
_dot_directory $directory _dot_directory $directory
} }
function existing_emacs {
# Return any existing emacs server file or the one that should
# be created if it doesn't exist.
local server_file="$(\ls ~/.emacs.d/server | head -n1)"
[ -z "$server_file" ] && server_file="$(_emacs_server_file)"
echo $server_file
}
function emacs_make_frame_if_none_exists {
emacsclient -e '(make-frame-if-none-exists)' --server-file=$1
}
function get_running_emacs_instances {
pgrep -i emacs | xargs ps -o command -p | egrep -o " --daemon=(.*)" | awk -F= '{print $2}' | sed 's/\^J3,4\^J//'
}
function emacs_open {
local server_file="$(get_running_emacs_instances | head -n1)"
if [ -z $server_file ]; then
_emacs -c -n "$@"
return
fi
emacs_make_frame_if_none_exists $server_file
[ ! -z "$@" ] && emacsclient "$@" -n --server-file="$server_file"
}
# Make emacs the default editor. # Make emacs the default editor.
export EDITOR="$(which emacsclient) -n -s " export EDITOR="$(which emacsclient) -n -s "
export ALTERNATE_EDITOR="" export ALTERNATE_EDITOR=""

View File

@ -83,3 +83,64 @@ function set_osx_hostname() {
sudo scutil --set LocalHostName $new_hostname sudo scutil --set LocalHostName $new_hostname
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $new_hostname sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $new_hostname
} }
function get_bundle_identifier() {
defaults read "$1/Contents/Info" CFBundleIdentifier
}
_BUDDY="/usr/libexec/PlistBuddy"
_PLIST="$HOME/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist"
function create_filename_rule {
$_BUDDY -c "Add LSHandlers:0 dict" $_PLIST
$_BUDDY -c "Add LSHandlers:0:LSHandlerRoleAll string $1" $_PLIST
$_BUDDY -c "Add LSHandlers:0:LSHandlerContentTag string $2" $_PLIST
$_BUDDY -c "Add LSHandlers:0:LSHandlerContentTagClass string public.filename-extension" $_PLIST
$_BUDDY -c "Add LSHandlers:0:LSHandlerPreferredVersions dict" $_PLIST
$_BUDDY -c "Add LSHandlers:0:LSHandlerPreferredVersions:LSHandlerRoleAll string -" $_PLIST
}
function set_application_for_file_extension() {
local PLIST="$HOME/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist"
# the key to match with the desired value
KEY="LSHandlerContentType"
# the value for which we'll replace the handler
VALUE="${1-public.plain-text}"
# the new handler for all roles
HANDLER="${1}"
$_BUDDY -c 'Print "LSHandlers"' $_PLIST >/dev/null 2>&1
if [[ $? -ne 0 ]] ; then
echo "There is no LSHandlers entry in $_PLIST" >&2
exit 1
fi
declare -i I=0
while [ true ] ; do
$_BUDDY -c "Print LSHandlers:$I" $_PLIST >/dev/null 2>&1
[[ $? -eq 0 ]] || { echo "Finished, no $VALUE found, setting it to $HANDLER" ; create_entry ; exit ; }
OUT="$( $_BUDDY -c "Print 'LSHandlers:$I:$KEY'" $_PLIST 2>/dev/null )"
if [[ $? -ne 0 ]] ; then
I=$I+1
continue
fi
CONTENT=$( echo "$OUT" )
if [[ $CONTENT = $VALUE ]] ; then
echo "Replacing $CONTENT handler with $HANDLER"
$_BUDDY -c "Delete 'LSHandlers:$I'" $_PLIST
create_entry
exit
else
I=$I+1
fi
done
}
function reload_preferences {
killall -u $(whoami) cfprefsd
}

View File

@ -129,14 +129,10 @@ function separator {
export JOB_COUNT_COLOR="$fg[blue]" export JOB_COUNT_COLOR="$fg[blue]"
prompt_tomorrow_colors prompt_tomorrow_colors
# For reasons which are currently beyond me, # For reasons which are currently beyond me, it is not possible to use
# $? in PROMPT which is why the second line is so strangely
# constructed.
export PROMPT='⚡ % $(print_with_color "%n" "$USERNAME_COLOR") $(separator "at") $(print_with_color "`hostname -s`" "$HOSTNAME_COLOR") $(separator "in") $(print_with_color "`current_directory`" "$CURRENT_DIRECTORY_COLOR")$(git_prompt_info) export PROMPT='⚡ % $(print_with_color "%n" "$USERNAME_COLOR") $(separator "at") $(print_with_color "`hostname -s`" "$HOSTNAME_COLOR") $(separator "in") $(print_with_color "`current_directory`" "$CURRENT_DIRECTORY_COLOR")$(git_prompt_info)
$(colored_job_count)%(?.$(print_with_color "$(command_line_character) " $PROMPT_CHAR_SUCCESS).$(print_with_color "$(command_line_character) " $PROMPT_CHAR_ERROR)) ' $(colored_job_count)%(?.$(print_with_color "$(command_line_character) " $PROMPT_CHAR_SUCCESS).$(print_with_color "$(command_line_character) " $PROMPT_CHAR_ERROR)) '
PS2='(%_) ' PS2='(%_) '
case "$TERM" in
dumb)
export PROMPT='> '
;;
esac

View File

@ -1,5 +1,5 @@
# This is necessary for tramp. # This is necessary for tramp.
[[ $TERM == "dumb" ]] && unsetopt zle && PS1='$ ' && return
source ~/.lib/shellrc.sh source ~/.lib/shellrc.sh
[[ $TERM == "dumb" ]] && unsetopt zle && PS1='$ ' && return
source ~/.lib/zsh.sh source ~/.lib/zsh.sh
test -r ~/custom.zsh && source ~/custom.zsh test -r ~/custom.zsh && source ~/custom.zsh

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AMIsApplet</key>
<true/>
<key>AMStayOpen</key>
<false/>
<key>BuildMachineOSBuild</key>
<string>14A359</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>*</string>
</array>
<key>CFBundleTypeName</key>
<string>Automator workflow file</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>Application Stub</string>
<key>CFBundleIconFile</key>
<string>AutomatorApplet</string>
<key>CFBundleIdentifier</key>
<string>com.apple.automator.Emacs</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Emacs</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array/>
<key>CFBundleVersion</key>
<string>409</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>6A280m</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>14A359</string>
<key>DTSDKName</key>
<string>macosx10.10internal</string>
<key>DTXcode</key>
<string>0600</string>
<key>DTXcodeBuild</key>
<string>6A280m</string>
<key>LSMinimumSystemVersion</key>
<string>10.5</string>
<key>LSMinimumSystemVersionByArchitecture</key>
<dict>
<key>x86_64</key>
<string>10.6</string>
</dict>
<key>LSUIElement</key>
<true/>
<key>NSAppleScriptEnabled</key>
<string>YES</string>
<key>NSMainNibFile</key>
<string>ApplicationStub</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSServices</key>
<array/>
<key>UTExportedTypeDeclarations</key>
<array/>
<key>UTImportedTypeDeclarations</key>
<array/>
</dict>
</plist>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,194 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AMApplicationBuild</key>
<string>409</string>
<key>AMApplicationVersion</key>
<string>2.5</string>
<key>AMDocumentVersion</key>
<string>2</string>
<key>actions</key>
<array>
<dict>
<key>action</key>
<dict>
<key>AMAccepts</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Optional</key>
<true/>
<key>Types</key>
<array>
<string>com.apple.cocoa.string</string>
</array>
</dict>
<key>AMActionVersion</key>
<string>2.0.3</string>
<key>AMApplication</key>
<array>
<string>Automator</string>
</array>
<key>AMParameterProperties</key>
<dict>
<key>COMMAND_STRING</key>
<dict/>
<key>CheckedForUserDefaultShell</key>
<dict/>
<key>inputMethod</key>
<dict/>
<key>shell</key>
<dict/>
<key>source</key>
<dict/>
</dict>
<key>AMProvides</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Types</key>
<array>
<string>com.apple.cocoa.string</string>
</array>
</dict>
<key>ActionBundlePath</key>
<string>/System/Library/Automator/Run Shell Script.action</string>
<key>ActionName</key>
<string>Run Shell Script</string>
<key>ActionParameters</key>
<dict>
<key>COMMAND_STRING</key>
<string>source ~/.zshrc
emacs_open "$@"</string>
<key>CheckedForUserDefaultShell</key>
<true/>
<key>inputMethod</key>
<integer>1</integer>
<key>shell</key>
<string>/bin/zsh</string>
<key>source</key>
<string></string>
</dict>
<key>BundleIdentifier</key>
<string>com.apple.RunShellScript</string>
<key>CFBundleVersion</key>
<string>2.0.3</string>
<key>CanShowSelectedItemsWhenRun</key>
<false/>
<key>CanShowWhenRun</key>
<true/>
<key>Category</key>
<array>
<string>AMCategoryUtilities</string>
</array>
<key>Class Name</key>
<string>RunShellScriptAction</string>
<key>InputUUID</key>
<string>DA055C0F-4655-4BE5-A48B-D59E2E2EA521</string>
<key>Keywords</key>
<array>
<string>Shell</string>
<string>Script</string>
<string>Command</string>
<string>Run</string>
<string>Unix</string>
</array>
<key>OutputUUID</key>
<string>EE1103A5-74E2-4582-A3C4-D2B49F943409</string>
<key>UUID</key>
<string>47374D23-F3C7-4112-AFEB-5874CB21FD05</string>
<key>UnlocalizedApplications</key>
<array>
<string>Automator</string>
</array>
<key>arguments</key>
<dict>
<key>0</key>
<dict>
<key>default value</key>
<integer>0</integer>
<key>name</key>
<string>inputMethod</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>0</string>
</dict>
<key>1</key>
<dict>
<key>default value</key>
<string></string>
<key>name</key>
<string>source</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>1</string>
</dict>
<key>2</key>
<dict>
<key>default value</key>
<false/>
<key>name</key>
<string>CheckedForUserDefaultShell</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>2</string>
</dict>
<key>3</key>
<dict>
<key>default value</key>
<string></string>
<key>name</key>
<string>COMMAND_STRING</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>3</string>
</dict>
<key>4</key>
<dict>
<key>default value</key>
<string>/bin/sh</string>
<key>name</key>
<string>shell</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>4</string>
</dict>
</dict>
<key>conversionLabel</key>
<integer>0</integer>
<key>isViewVisible</key>
<true/>
<key>location</key>
<string>448.000000:253.000000</string>
<key>nibPath</key>
<string>/System/Library/Automator/Run Shell Script.action/Contents/Resources/English.lproj/main.nib</string>
</dict>
<key>isViewVisible</key>
<true/>
</dict>
</array>
<key>connectors</key>
<dict/>
<key>workflowMetaData</key>
<dict>
<key>workflowTypeIdentifier</key>
<string>com.apple.Automator.application</string>
</dict>
</dict>
</plist>

View File