Code

git-gui: Create a .app file on MacOS X if requested.
authorShawn O. Pearce <spearce@spearce.org>
Sat, 18 Nov 2006 05:31:00 +0000 (00:31 -0500)
committerShawn O. Pearce <spearce@spearce.org>
Sat, 18 Nov 2006 05:31:00 +0000 (00:31 -0500)
If a user works with a repository frequently they may want to just
create an icon they can use to launch git-gui against that repository.

Since we already support this concept on Windows we can do the same on
Mac OS X by creating a .app file with a tiny shell script in it that
sets up the necessary environment then invokes our script.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
git-gui

diff --git a/git-gui b/git-gui
index ea60e327ead246e8c0df798602ec811105b590d6..472bcb7e32bee22cb58d5d7e5b0ad43a72c1c734 100755 (executable)
--- a/git-gui
+++ b/git-gui
@@ -2114,6 +2114,79 @@ proc do_windows_shortcut {} {
        }
 }
 
+proc do_macosx_app {} {
+       global gitdir appname argv0 env
+
+       set reponame [lindex [file split \
+               [file normalize [file dirname $gitdir]]] \
+               end]
+
+       set fn [tk_getSaveFile \
+               -parent . \
+               -title "$appname ($reponame): Create Desktop Icon" \
+               -initialdir [file join $env(HOME) Desktop] \
+               -initialfile "Git $reponame.app"]
+       if {$fn != {}} {
+               if {[catch {
+                               set Contents [file join $fn Contents]
+                               set MacOS [file join $Contents MacOS]
+                               set exe [file join $MacOS git-gui]
+
+                               file mkdir $MacOS
+
+                               set fd [open [file join $Contents PkgInfo] w]
+                               puts -nonewline $fd {APPL????}
+                               close $fd
+
+                               set fd [open [file join $Contents Info.plist] w]
+                               puts $fd {<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>CFBundleDevelopmentRegion</key>
+       <string>English</string>
+       <key>CFBundleExecutable</key>
+       <string>git-gui</string>
+       <key>CFBundleIdentifier</key>
+       <string>org.spearce.git-gui</string>
+       <key>CFBundleInfoDictionaryVersion</key>
+       <string>6.0</string>
+       <key>CFBundlePackageType</key>
+       <string>APPL</string>
+       <key>CFBundleSignature</key>
+       <string>????</string>
+       <key>CFBundleVersion</key>
+       <string>1.0</string>
+       <key>NSPrincipalClass</key>
+       <string>NSApplication</string>
+</dict>
+</plist>}
+                               close $fd
+
+                               set fd [open $exe w]
+                               set gd [file normalize $gitdir]
+                               set ep [file normalize [exec git --exec-path]]
+                               regsub -all ' $gd "'\\''" gd
+                               regsub -all ' $ep "'\\''" ep
+                               puts $fd "#!/bin/sh"
+                               foreach name [array names env] {
+                                       if {[string match GIT_* $name]} {
+                                               regsub -all ' $env($name) "'\\''" v
+                                               puts $fd "export $name='$v'"
+                                       }
+                               }
+                               puts $fd "export PATH='$ep':\$PATH"
+                               puts $fd "export GIT_DIR='$gd'"
+                               puts $fd "exec [file normalize $argv0]"
+                               close $fd
+
+                               file attributes $exe -permissions u+x,g+x,o+x
+                       } err]} {
+                       error_popup "Cannot write icon:\n\n$err"
+               }
+       }
+}
+
 proc toggle_or_diff {w x y} {
        global file_lists ui_index ui_other
        global last_clicked selected_paths
@@ -2286,6 +2359,11 @@ if {!$single_commit} {
                        -label {Create Desktop Icon} \
                        -command do_windows_shortcut \
                        -font font_ui
+       } elseif {[is_MacOSX]} {
+               .mbar.project add command \
+                       -label {Create Desktop Icon} \
+                       -command do_macosx_app \
+                       -font font_ui
        }
 }
 .mbar.project add command -label Quit \