Merge branch 'dp/submodule-doc-markup-fix'
[git] / git-gui / lib / shortcut.tcl
1 # git-gui desktop icon creators
2 # Copyright (C) 2006, 2007 Shawn Pearce
3
4 proc do_windows_shortcut {} {
5         global _gitworktree
6         set fn [tk_getSaveFile \
7                 -parent . \
8                 -title [mc "%s (%s): Create Desktop Icon" [appname] [reponame]] \
9                 -initialfile "Git [reponame].lnk"]
10         if {$fn != {}} {
11                 if {[file extension $fn] ne {.lnk}} {
12                         set fn ${fn}.lnk
13                 }
14                 # Use git-gui.exe if available (ie: git-for-windows)
15                 set cmdLine [auto_execok git-gui.exe]
16                 if {$cmdLine eq {}} {
17                         set cmdLine [list [info nameofexecutable] \
18                                                          [file normalize $::argv0]]
19                 }
20                 if {[catch {
21                                 win32_create_lnk $fn $cmdLine \
22                                         [file normalize $_gitworktree]
23                         } err]} {
24                         error_popup [strcat [mc "Cannot write shortcut:"] "\n\n$err"]
25                 }
26         }
27 }
28
29 proc do_cygwin_shortcut {} {
30         global argv0 _gitworktree
31
32         if {[catch {
33                 set desktop [exec cygpath \
34                         --windows \
35                         --absolute \
36                         --long-name \
37                         --desktop]
38                 }]} {
39                         set desktop .
40         }
41         set fn [tk_getSaveFile \
42                 -parent . \
43                 -title [mc "%s (%s): Create Desktop Icon" [appname] [reponame]] \
44                 -initialdir $desktop \
45                 -initialfile "Git [reponame].lnk"]
46         if {$fn != {}} {
47                 if {[file extension $fn] ne {.lnk}} {
48                         set fn ${fn}.lnk
49                 }
50                 if {[catch {
51                                 set sh [exec cygpath \
52                                         --windows \
53                                         --absolute \
54                                         /bin/sh.exe]
55                                 set me [exec cygpath \
56                                         --unix \
57                                         --absolute \
58                                         $argv0]
59                                 win32_create_lnk $fn [list \
60                                         $sh -c \
61                                         "CHERE_INVOKING=1 source /etc/profile;[sq $me] &" \
62                                         ] \
63                                         [file normalize $_gitworktree]
64                         } err]} {
65                         error_popup [strcat [mc "Cannot write shortcut:"] "\n\n$err"]
66                 }
67         }
68 }
69
70 proc do_macosx_app {} {
71         global argv0 env
72
73         set fn [tk_getSaveFile \
74                 -parent . \
75                 -title [mc "%s (%s): Create Desktop Icon" [appname] [reponame]] \
76                 -initialdir [file join $env(HOME) Desktop] \
77                 -initialfile "Git [reponame].app"]
78         if {$fn != {}} {
79                 if {[file extension $fn] ne {.app}} {
80                         set fn ${fn}.app
81                 }
82                 if {[catch {
83                                 set Contents [file join $fn Contents]
84                                 set MacOS [file join $Contents MacOS]
85                                 set exe [file join $MacOS git-gui]
86
87                                 file mkdir $MacOS
88
89                                 set fd [open [file join $Contents Info.plist] w]
90                                 puts $fd {<?xml version="1.0" encoding="UTF-8"?>
91 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
92 <plist version="1.0">
93 <dict>
94         <key>CFBundleDevelopmentRegion</key>
95         <string>English</string>
96         <key>CFBundleExecutable</key>
97         <string>git-gui</string>
98         <key>CFBundleIdentifier</key>
99         <string>org.spearce.git-gui</string>
100         <key>CFBundleInfoDictionaryVersion</key>
101         <string>6.0</string>
102         <key>CFBundlePackageType</key>
103         <string>APPL</string>
104         <key>CFBundleSignature</key>
105         <string>????</string>
106         <key>CFBundleVersion</key>
107         <string>1.0</string>
108         <key>NSPrincipalClass</key>
109         <string>NSApplication</string>
110 </dict>
111 </plist>}
112                                 close $fd
113
114                                 set fd [open $exe w]
115                                 puts $fd "#!/bin/sh"
116                                 foreach name [lsort [array names env]] {
117                                         set value $env($name)
118                                         switch -- $name {
119                                         GIT_DIR { set value [file normalize [gitdir]] }
120                                         }
121
122                                         switch -glob -- $name {
123                                         SSH_* -
124                                         GIT_* {
125                                                 puts $fd "if test \"z\$$name\" = z; then"
126                                                 puts $fd "  export $name=[sq $value]"
127                                                 puts $fd "fi &&"
128                                         }
129                                         }
130                                 }
131                                 puts $fd "export PATH=[sq [file dirname $::_git]]:\$PATH &&"
132                                 puts $fd "cd [sq [file normalize [pwd]]] &&"
133                                 puts $fd "exec \\"
134                                 puts $fd " [sq [info nameofexecutable]] \\"
135                                 puts $fd " [sq [file normalize $argv0]]"
136                                 close $fd
137
138                                 file attributes $exe -permissions u+x,g+x,o+x
139                         } err]} {
140                         error_popup [strcat [mc "Cannot write icon:"] "\n\n$err"]
141                 }
142         }
143 }