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