@matheusbsbs / matheus-bagliano / commits / 06c311157a
Fork 0

git-gui: Create a .app file on MacOS X if requested.

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>

Shawn O. Pearce committed Nov 18, 2006 at 00:31 UTC 06c311157a045c2189acc5496fdc71a806c28f8c
1 file changed +78
git-gui
+78
@@ -2114,6 +2114,79 @@ proc do_windows_shortcut {} {
2114 }
2115 }
2116
2117 +proc do_macosx_app {} {
2118 + global gitdir appname argv0 env
2119 +
2120 + set reponame [lindex [file split \
2121 + [file normalize [file dirname $gitdir]]] \
2122 + end]
2123 +
2124 + set fn [tk_getSaveFile \
2125 + -parent . \
2126 + -title "$appname ($reponame): Create Desktop Icon" \
2127 + -initialdir [file join $env(HOME) Desktop] \
2128 + -initialfile "Git $reponame.app"]
2129 + if {$fn != {}} {
2130 + if {[catch {
2131 + set Contents [file join $fn Contents]
2132 + set MacOS [file join $Contents MacOS]
2133 + set exe [file join $MacOS git-gui]
2134 +
2135 + file mkdir $MacOS
2136 +
2137 + set fd [open [file join $Contents PkgInfo] w]
2138 + puts -nonewline $fd {APPL????}
2139 + close $fd
2140 +
2141 + set fd [open [file join $Contents Info.plist] w]
2142 + puts $fd {<?xml version="1.0" encoding="UTF-8"?>
2143 +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2144 +<plist version="1.0">
2145 +<dict>
2146 + <key>CFBundleDevelopmentRegion</key>
2147 + <string>English</string>
2148 + <key>CFBundleExecutable</key>
2149 + <string>git-gui</string>
2150 + <key>CFBundleIdentifier</key>
2151 + <string>org.spearce.git-gui</string>
2152 + <key>CFBundleInfoDictionaryVersion</key>
2153 + <string>6.0</string>
2154 + <key>CFBundlePackageType</key>
2155 + <string>APPL</string>
2156 + <key>CFBundleSignature</key>
2157 + <string>????</string>
2158 + <key>CFBundleVersion</key>
2159 + <string>1.0</string>
2160 + <key>NSPrincipalClass</key>
2161 + <string>NSApplication</string>
2162 +</dict>
2163 +</plist>}
2164 + close $fd
2165 +
2166 + set fd [open $exe w]
2167 + set gd [file normalize $gitdir]
2168 + set ep [file normalize [exec git --exec-path]]
2169 + regsub -all ' $gd "'\\''" gd
2170 + regsub -all ' $ep "'\\''" ep
2171 + puts $fd "#!/bin/sh"
2172 + foreach name [array names env] {
2173 + if {[string match GIT_* $name]} {
2174 + regsub -all ' $env($name) "'\\''" v
2175 + puts $fd "export $name='$v'"
2176 + }
2177 + }
2178 + puts $fd "export PATH='$ep':\$PATH"
2179 + puts $fd "export GIT_DIR='$gd'"
2180 + puts $fd "exec [file normalize $argv0]"
2181 + close $fd
2182 +
2183 + file attributes $exe -permissions u+x,g+x,o+x
2184 + } err]} {
2185 + error_popup "Cannot write icon:\n\n$err"
2186 + }
2187 + }
2188 +}
2189 +
2190 proc toggle_or_diff {w x y} {
2191 global file_lists ui_index ui_other
2192 global last_clicked selected_paths
@@ -2286,6 +2359,11 @@ if {!$single_commit} {
2359 -label {Create Desktop Icon} \
2360 -command do_windows_shortcut \
2361 -font font_ui
2362 + } elseif {[is_MacOSX]} {
2363 + .mbar.project add command \
2364 + -label {Create Desktop Icon} \
2365 + -command do_macosx_app \
2366 + -font font_ui
2367 }
2368 }
2369 .mbar.project add command -label Quit \