Git fork
at reftables-rust 154 lines 4.2 kB view raw
1# git-gui desktop icon creators 2# Copyright (C) 2006, 2007 Shawn Pearce 3 4proc do_windows_shortcut {} { 5 global _gitworktree 6 7 set desktop [safe_exec [list cygpath -mD]] 8 set link_file "Git [reponame].lnk" 9 set link_path [file normalize [file join $desktop $link_file]] 10 11 # on Windows, tk_getSaveFile dereferences .lnk files, so no simple 12 # filename chooser is available. Use the default or quit. 13 if {[file exists $link_path]} { 14 set answer [tk_messageBox \ 15 -type yesno \ 16 -title [mc "%s (%s): Create Desktop Icon" [appname] [reponame]] \ 17 -default yes \ 18 -message [mc "Replace existing shortcut: %s?" $link_file]] 19 if {$answer == no} { 20 return 21 } 22 } 23 24 # Use git-gui.exe if found, fall back to wish + launcher 25 set link_arguments {} 26 set link_target [safe_exec [list cygpath -m /cmd/git-gui.exe]] 27 if {![file executable $link_target]} { 28 set link_target [_which git-gui] 29 } 30 if {![file executable $link_target]} { 31 set link_target [file normalize [info nameofexecutable]] 32 set link_arguments [file normalize $::argv0] 33 } 34 set cmdLine [list $link_target $link_arguments] 35 if {[catch { 36 win32_create_lnk $link_path $cmdLine \ 37 [file normalize $_gitworktree] 38 } err]} { 39 error_popup [strcat [mc "Cannot write shortcut:"] "\n\n$err"] 40 } 41} 42 43proc do_cygwin_shortcut {} { 44 global argv0 _gitworktree oguilib 45 46 if {[catch { 47 set desktop [safe_exec [list cygpath \ 48 --desktop]] 49 }]} { 50 set desktop . 51 } 52 set fn [tk_getSaveFile \ 53 -parent . \ 54 -title [mc "%s (%s): Create Desktop Icon" [appname] [reponame]] \ 55 -initialdir $desktop \ 56 -initialfile "Git [reponame].lnk"] 57 if {$fn != {}} { 58 if {[file extension $fn] ne {.lnk}} { 59 set fn ${fn}.lnk 60 } 61 if {[catch { 62 set repodir [file normalize $_gitworktree] 63 set shargs {-c \ 64 "CHERE_INVOKING=1 \ 65 source /etc/profile; \ 66 git gui"} 67 safe_exec [list /bin/mkshortcut.exe \ 68 --arguments $shargs \ 69 --desc "git-gui on $repodir" \ 70 --icon $oguilib/git-gui.ico \ 71 --name $fn \ 72 --show min \ 73 --workingdir $repodir \ 74 /bin/sh.exe] 75 } err]} { 76 error_popup [strcat [mc "Cannot write shortcut:"] "\n\n$err"] 77 } 78 } 79} 80 81proc do_macosx_app {} { 82 global argv0 env 83 84 set fn [tk_getSaveFile \ 85 -parent . \ 86 -title [mc "%s (%s): Create Desktop Icon" [appname] [reponame]] \ 87 -initialdir [file join $env(HOME) Desktop] \ 88 -initialfile "Git [reponame].app"] 89 if {$fn != {}} { 90 if {[file extension $fn] ne {.app}} { 91 set fn ${fn}.app 92 } 93 if {[catch { 94 set Contents [file join $fn Contents] 95 set MacOS [file join $Contents MacOS] 96 set exe [file join $MacOS git-gui] 97 98 file mkdir $MacOS 99 100 set fd [safe_open_file [file join $Contents Info.plist] w] 101 puts $fd {<?xml version="1.0" encoding="UTF-8"?> 102<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 103<plist version="1.0"> 104<dict> 105 <key>CFBundleDevelopmentRegion</key> 106 <string>English</string> 107 <key>CFBundleExecutable</key> 108 <string>git-gui</string> 109 <key>CFBundleIdentifier</key> 110 <string>org.spearce.git-gui</string> 111 <key>CFBundleInfoDictionaryVersion</key> 112 <string>6.0</string> 113 <key>CFBundlePackageType</key> 114 <string>APPL</string> 115 <key>CFBundleSignature</key> 116 <string>????</string> 117 <key>CFBundleVersion</key> 118 <string>1.0</string> 119 <key>NSPrincipalClass</key> 120 <string>NSApplication</string> 121</dict> 122</plist>} 123 close $fd 124 125 set fd [safe_open_file $exe w] 126 puts $fd "#!/bin/sh" 127 foreach name [lsort [array names env]] { 128 set value $env($name) 129 switch -- $name { 130 GIT_DIR { set value [file normalize [gitdir]] } 131 } 132 133 switch -glob -- $name { 134 SSH_* - 135 GIT_* { 136 puts $fd "if test \"z\$$name\" = z; then" 137 puts $fd " export $name=[sq $value]" 138 puts $fd "fi &&" 139 } 140 } 141 } 142 puts $fd "export PATH=[sq [file dirname $::_git]]:\$PATH &&" 143 puts $fd "cd [sq [file normalize [pwd]]] &&" 144 puts $fd "exec \\" 145 puts $fd " [sq [info nameofexecutable]] \\" 146 puts $fd " [sq [file normalize $argv0]]" 147 close $fd 148 149 file attributes $exe -permissions u+x,g+x,o+x 150 } err]} { 151 error_popup [strcat [mc "Cannot write icon:"] "\n\n$err"] 152 } 153 } 154}