├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── entrypoint.sh └── xcgo.zsh-theme /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | 17 | xcgo.iml 18 | .DS_Store -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # This neilotoole/xcgo Dockerfile builds a maximalist Go/Golang CGo-enabled 2 | # cross-compiling image It can build CGo apps on macOS, Linux, and Windows. 3 | # It also contains supporting tools such as docker and snapcraft. 4 | # See https://github.com/neilotoole/xcgo 5 | ARG OSX_SDK="MacOSX10.15.sdk" 6 | ARG OSX_CODENAME="catalina" 7 | ARG OSX_VERSION_MIN="10.10" 8 | ARG OSX_SDK_BASEURL="https://github.com/neilotoole/xcgo/releases/download/v0.1" 9 | ARG OSX_SDK_SUM="d97054a0aaf60cb8e9224ec524315904f0309fbbbac763eb7736bdfbdad6efc8" 10 | ARG OSX_CROSS_COMMIT="de6ec57895713a090fee05cbc58e43b5d916ba33" 11 | ARG LIBTOOL_VERSION="2.4.6_1" 12 | ARG LIBTOOL_BASEURL="https://github.com/neilotoole/xcgo/releases/download/v0.1" 13 | ARG GOLANGCI_LINT_VERSION="1.42.1" 14 | ARG GORELEASER_VERSION="0.182.1" 15 | ARG GO_VERSION="" 16 | ARG UBUNTU=bionic 17 | 18 | 19 | 20 | #################### snapbuilder #################### 21 | FROM ubuntu:${UBUNTU} AS snapbuilder 22 | ARG UBUNTU 23 | # We build from ubuntu because we need snapcraft. It's difficult 24 | # to build, say, a Debian-based image with snapcraft included. Note also that 25 | # the snapcore/snapcraft images are based upon ubuntu:xenial, but we 26 | # want ubuntu:bionic (some things we want, e.g. go1.14, don't have good 27 | # packages for xenial at the time of writing). 28 | 29 | # This section lifted from snapcore/snapcraft:stable 30 | # Grab dependencies 31 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y \ 32 | curl \ 33 | jq \ 34 | lsb-core \ 35 | squashfs-tools 36 | 37 | 38 | # Grab the core snap (for backwards compatibility) from the stable channel and 39 | # unpack it in the proper place. 40 | RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/core' | jq '.download_url' -r) --output core.snap 41 | RUN mkdir -p /snap/core 42 | RUN unsquashfs -d /snap/core/current core.snap 43 | 44 | # Grab the core18 snap (which snapcraft uses as a base) from the stable channel 45 | # and unpack it in the proper place. 46 | RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/core18' | jq '.download_url' -r) --output core18.snap 47 | RUN mkdir -p /snap/core18 48 | RUN unsquashfs -d /snap/core18/current core18.snap 49 | 50 | # Grab the snapcraft snap from the stable channel and unpack it in the proper 51 | # place. 52 | RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/snapcraft?channel=stable' | jq '.download_url' -r) --output snapcraft.snap 53 | RUN mkdir -p /snap/snapcraft 54 | RUN unsquashfs -d /snap/snapcraft/current snapcraft.snap 55 | 56 | # Create a snapcraft runner 57 | RUN mkdir -p /snap/bin 58 | RUN echo "#!/bin/sh" > /snap/bin/snapcraft 59 | RUN snap_version="$(awk '/^version:/{print $2}' /snap/snapcraft/current/meta/snap.yaml)" && echo "export SNAP_VERSION=\"$snap_version\"" >> /snap/bin/snapcraft 60 | RUN echo 'exec "$SNAP/usr/bin/python3" "$SNAP/bin/snapcraft" "$@"' >> /snap/bin/snapcraft 61 | RUN chmod +x /snap/bin/snapcraft 62 | 63 | ## Multi-stage build, only need the snaps from the builder. Copy them one at a 64 | ## time so they can be cached. 65 | FROM ubuntu:$UBUNTU AS snapcore 66 | COPY --from=snapbuilder /snap/core /snap/core 67 | COPY --from=snapbuilder /snap/core18 /snap/core18 68 | COPY --from=snapbuilder /snap/snapcraft /snap/snapcraft 69 | COPY --from=snapbuilder /snap/bin/snapcraft /snap/bin/snapcraft 70 | 71 | # Generate locale and install dependencies. 72 | RUN apt-get update && apt-get dist-upgrade --yes && apt-get install --yes snapd sudo locales && locale-gen en_US.UTF-8 73 | 74 | # Set the proper environment. 75 | ENV LANG="en_US.UTF-8" 76 | ENV LANGUAGE="en_US:en" 77 | ENV LC_ALL="en_US.UTF-8" 78 | ENV PATH="/snap/bin:$PATH" 79 | ENV SNAP="/snap/snapcraft/current" 80 | ENV SNAP_NAME="snapcraft" 81 | ENV SNAP_ARCH="amd64" 82 | 83 | #################### golangcore #################### 84 | FROM snapcore AS golangcore 85 | ARG GO_VERSION 86 | RUN apt-get update && apt-get install -y --no-install-recommends \ 87 | curl \ 88 | git \ 89 | jq \ 90 | lsb-core \ 91 | software-properties-common 92 | 93 | ENV GOPATH="/go" 94 | RUN mkdir -p "${GOPATH}/src" 95 | 96 | # As suggested here: https://github.com/golang/go/wiki/Ubuntu 97 | RUN add-apt-repository -y ppa:longsleep/golang-backports 98 | RUN if test -z "${GO_VERSION}"; then GO_VERSION=$(curl 'https://go.dev/VERSION?m=text'); fi && \ 99 | curl -L -o go.tar.gz https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz && \ 100 | rm -rf /usr/local/go && tar -C /usr/local -xzf go.tar.gz && \ 101 | rm go.tar.gz 102 | RUN ln -s /usr/local/go /usr/lib/go 103 | RUN ln -s /usr/local/go/bin/go /usr/bin/go 104 | RUN ln -s /usr/local/go/bin/gofmt /usr/bin/gofmt 105 | 106 | RUN go version 107 | 108 | 109 | #################### devtools #################### 110 | FROM golangcore AS devtools 111 | # Dependencies for https://github.com/tpoechtrager/osxcross and some 112 | # other stuff. 113 | 114 | RUN apt-get update && apt-get install -y --no-install-recommends \ 115 | build-essential \ 116 | clang \ 117 | cmake \ 118 | file \ 119 | gcc-mingw-w64 gcc-mingw-w64-i686 gcc-mingw-w64-x86-64 \ 120 | less \ 121 | libc6-dev \ 122 | libc6-dev-i386 \ 123 | libc++-dev \ 124 | libltdl-dev \ 125 | libsqlite3-dev \ 126 | libssl-dev \ 127 | libxml2-dev \ 128 | llvm \ 129 | man \ 130 | parallel \ 131 | patch \ 132 | sqlite3 \ 133 | tree \ 134 | vim \ 135 | wget \ 136 | xz-utils \ 137 | zlib1g-dev \ 138 | zsh 139 | 140 | 141 | 142 | #################### osx-cross #################### 143 | # See https://github.com/tpoechtrager/osxcross 144 | FROM devtools AS osx-cross 145 | ARG OSX_SDK 146 | ARG OSX_CODENAME 147 | ARG OSX_SDK_BASEURL 148 | ARG OSX_SDK_SUM 149 | ARG OSX_CROSS_COMMIT 150 | ARG OSX_VERSION_MIN 151 | ARG LIBTOOL_VERSION 152 | ARG LIBTOOL_BASEURL 153 | ENV OSX_CROSS_PATH=/osxcross 154 | 155 | WORKDIR "${OSX_CROSS_PATH}" 156 | RUN git clone https://github.com/tpoechtrager/osxcross.git . \ 157 | && git checkout -q "${OSX_CROSS_COMMIT}" \ 158 | && rm -rf ./.git 159 | 160 | RUN curl -fsSL "${OSX_SDK_BASEURL}/${OSX_SDK}.tar.xz" -o "${OSX_CROSS_PATH}/tarballs/${OSX_SDK}.tar.xz" 161 | RUN echo "${OSX_SDK_SUM}" "${OSX_CROSS_PATH}/tarballs/${OSX_SDK}.tar.xz" | sha256sum -c - 162 | 163 | RUN UNATTENDED=yes OSX_VERSION_MIN=${OSX_VERSION_MIN} ./build.sh 164 | 165 | RUN mkdir -p "${OSX_CROSS_PATH}/target/SDK/${OSX_SDK}/usr/" 166 | RUN curl -fsSL "${LIBTOOL_BASEURL}/libtool-${LIBTOOL_VERSION}.${OSX_CODENAME}.bottle.tar.gz" \ 167 | | gzip -dc | tar xf - \ 168 | -C "${OSX_CROSS_PATH}/target/SDK/${OSX_SDK}/usr/" \ 169 | --strip-components=2 \ 170 | "libtool/${LIBTOOL_VERSION}/include/" \ 171 | "libtool/${LIBTOOL_VERSION}/lib/" 172 | 173 | WORKDIR /root 174 | 175 | 176 | 177 | #################### docker #################### 178 | FROM osx-cross AS docker 179 | RUN apt-get update -y && apt-get install -y --no-install-recommends \ 180 | apt-transport-https \ 181 | ca-certificates \ 182 | gnupg-agent 183 | 184 | 185 | RUN curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add - && \ 186 | add-apt-repository \ 187 | "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ 188 | $(lsb_release -cs) \ 189 | stable" 190 | 191 | RUN apt-get update && apt-get install -y docker-ce docker-ce-cli 192 | 193 | 194 | 195 | #################### gotools #################### 196 | FROM docker AS gotools 197 | # This section descended from https://github.com/mailchain/goreleaser-xcgo 198 | # Much gratitude to the mailchain team. 199 | ARG GORELEASER_VERSION 200 | ARG GORELEASER_DOWNLOAD_FILE="goreleaser_Linux_x86_64.tar.gz" 201 | ARG GORELEASER_DOWNLOAD_URL="https://github.com/goreleaser/goreleaser/releases/download/v${GORELEASER_VERSION}/${GORELEASER_DOWNLOAD_FILE}" 202 | ARG GOLANGCI_LINT_VERSION 203 | 204 | RUN wget "${GORELEASER_DOWNLOAD_URL}"; \ 205 | tar -xzf $GORELEASER_DOWNLOAD_FILE -C /usr/bin/ goreleaser; \ 206 | rm $GORELEASER_DOWNLOAD_FILE; 207 | 208 | # Add mage - https://magefile.org 209 | RUN cd /tmp && git clone https://github.com/magefile/mage.git && cd mage && go run bootstrap.go && rm -rf /tmp/mage 210 | 211 | # https://github.com/golangci/golangci-lint 212 | RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin "v${GOLANGCI_LINT_VERSION}" 213 | 214 | 215 | 216 | #################### xcgo-final #################### 217 | FROM gotools AS xcgo-final 218 | LABEL maintainer="neilotoole@apache.org" 219 | ENV PATH=${OSX_CROSS_PATH}/target/bin:$PATH:${GOPATH}/bin 220 | ENV CGO_ENABLED=1 221 | 222 | WORKDIR /root 223 | COPY ./entrypoint.sh /entrypoint.sh 224 | RUN chmod +x /entrypoint.sh 225 | ENTRYPOINT ["/entrypoint.sh"] 226 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Neil O'Toole 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # neilotoole/xcgo 2 | 3 | > **Note** 4 | > With the advent of the Apple Silicon architecture, this project has become even more work to maintain. 5 | > I originally developed `xcgo` as a build tool for [`sq`](https://github.com/neilotoole/sq), as 6 | > no other tool readily supported all of `sq`'s various build targets. However, recent releases 7 | > of [GoReleaser](https://goreleaser.com) plus GitHub workflows now satisify `sq`'s needs. This project will no longer 8 | > be actively maintained, although PRs will still be accepted. 9 | 10 | `xcgo` is a maximalist Docker image for cross-compiling and 11 | releasing/distributing CGo-enabled Go/Golang applications. At this time, it can build and dist 12 | macOS, Windows and Linux CGo projects for arch `amd64`. 13 | 14 | `xcgo` has what gophers crave: 15 | 16 | - `go 1.17` 17 | - `OSX SDK` Catalina / `macOS 10.15` (will build on later versions) 18 | - `docker` 19 | - `snapcraft` 20 | - `goreleaser` 21 | - `golangci-lint` 22 | - `mage` 23 | - `zsh` 24 | - and a bunch of other stuff. 25 | 26 | The primary source of documentation for `xcgo` is the [wiki](https://github.com/neilotoole/xcgo/wiki). 27 | Start there. There's a companion example project ([neilotoole/sqlitr](https://github.com/neilotoole/sqlitr)) 28 | that was created explicitly to exhibit `xcgo`: it demonstrates pretty much the entire array of `xcgo`'s capabilities, 29 | showing how to release to `brew`, `scoop`, `snap`, Docker Hub, GitHub, etc. The `neilotoole/xcgo` images are 30 | published to [Docker Hub](https://hub.docker.com/r/neilotoole/xcgo). 31 | 32 | > Note: No effort has yet been made to provide support for other 33 | > archs such as `386` (or for an OS beyond the typical three), 34 | > but pull requests are welcome. Note also that no effort has been 35 | > made to make this image slim. `xcgo` by mission is 36 | > maximalist (it's a 3GB+ image), but I'm sure the `Dockerfile` 37 | > can be slimmed down. Again, pull requests are welcome. 38 | 39 | ## Usage 40 | 41 | You can test `xcgo` with: 42 | 43 | ```shell script 44 | $ docker run -it neilotoole/xcgo:latest go version 45 | go version go1.17.2 linux/amd64 46 | ``` 47 | 48 | To play around in the container, launch into a shell: 49 | 50 | ```shell script 51 | $ docker run -it neilotoole/xcgo:latest zsh 52 | ``` 53 | 54 | `xcgo` doesn't prescribe a particular usage approach. Some possibilities: 55 | 56 | - Launch a container shell session, clone your repo, and build (or even edit and do all your work) within the container. 57 | - Mount your local repo into the container, shell in, and build from within the container. 58 | - With local repo mounted, invoke `xcgo` with `goreleaser`: this is pretty typical. 59 | 60 | ### Example: `go build` inside container 61 | 62 | From inside the docker container, we'll build (`amd64`) binaries for macOS, Linux, and Windows. 63 | 64 | Shell into the `xcgo` container if you haven't already done so: 65 | 66 | ```shell script 67 | $ docker run -it neilotoole/xcgo:latest zsh 68 | ``` 69 | 70 | From inside the container: 71 | 72 | ```shell script 73 | $ git clone https://github.com/neilotoole/sqlitr.git && cd sqlitr 74 | $ GOOS=darwin GOARCH=amd64 CC=o64-clang CXX=o64-clang++ go build -o dist/darwin_amd64/sqlitr 75 | $ GOOS=linux GOARCH=amd64 go build -o dist/linux_amd64/sqlitr 76 | $ GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -o dist/windows_amd64/sqlitr.exe 77 | ``` 78 | You should end up with something like this: 79 | 80 | ```shell script 81 | $ tree ./dist 82 | ./dist 83 | ├── darwin_amd64 84 | │   └── sqlitr 85 | ├── linux_amd64 86 | │   └── sqlitr 87 | └── windows_amd64 88 | └── sqlitr.exe 89 | ``` 90 | 91 | ### Example: `goreleaser` 92 | 93 | Quite possibly you'll want to use `xcgo` in conjunction 94 | with [goreleaser](http://goreleaser.com). 95 | 96 | Again, we'll use `sqlitr` to demonstrate. On your local machine, clone the `sqlitr` repo, mount it into the `xcgo` container and run `goreleaser`. 97 | 98 | ```shell script 99 | $ git clone https://github.com/neilotoole/sqlitr.git && cd sqlitr 100 | $ docker run --rm --privileged \ 101 | -v $(pwd):/go/src/github.com/neilotoole/sqlitr \ 102 | -v /var/run/docker.sock:/var/run/docker.sock \ 103 | -w /go/src/github.com/neilotoole/sqlitr \ 104 | neilotoole/xcgo:latest goreleaser --snapshot --rm-dist 105 | ``` 106 | 107 | The above will build that CGo project via `goreleaser` with binaries for macOS, Linux, and Windows. 108 | 109 | ```shell script 110 | $ tree ./dist 111 | ./dist 112 | ├── build_linux_linux_amd64 113 | │   └── sqlitr 114 | ├── build_macos_darwin_amd64 115 | │   └── sqlitr 116 | ├── build_windows_windows_amd64 117 | │   └── sqlitr.exe 118 | ├── checksums.txt 119 | ├── config.yaml 120 | ├── goreleaserdocker393975300 121 | │   ├── Dockerfile 122 | │   ├── LICENSE 123 | │   ├── README.md 124 | │   ├── sqlitr 125 | │   └── testdata 126 | │   └── example.sqlite 127 | ├── sqlitr_v0.1.23-snapshot_darwin_amd64.tar.gz 128 | ├── sqlitr_v0.1.23-snapshot_linux_amd64 129 | │   └── prime 130 | │   ├── meta 131 | │   │   └── snap.yaml 132 | │   └── sqlitr 133 | ├── sqlitr_v0.1.23-snapshot_linux_amd64.deb 134 | ├── sqlitr_v0.1.23-snapshot_linux_amd64.rpm 135 | ├── sqlitr_v0.1.23-snapshot_linux_amd64.snap 136 | ├── sqlitr_v0.1.23-snapshot_linux_amd64.tar.gz 137 | └── sqlitr_v0.1.23-snapshot_windows_amd64.zip 138 | ``` 139 | 140 | Again, see the [wiki](https://github.com/neilotoole/xcgo/wiki) for more. 141 | 142 | 143 | ## Parameterization 144 | Some params that can be passed to `xcgo` (as args to `docker run`): 145 | 146 | - **Docker:** `-e DOCKER_USERNAME=X -e DOCKER_PASSWORD=X` 147 | 148 | When present, `xcgo`'s `entrypoint.sh` performs a `docker login`. 149 | Supply `-e DOCKER_REGISTRY=X` to use a registry other than Docker Hub. 150 | 151 | - **GitHub:** `-e GITHUB_TOKEN=X` or `-e GORELEASER_GITHUB_TOKEN=X` 152 | 153 | Used to publish artifacts to GitHub (e.g. by `goreleaser`). 154 | 155 | - **Snapcraft:** `-v "${HOME}/.snapcraft.login":/.snapcraft.login` 156 | 157 | When `/.snapcraft.login` is present in the `xcgo` container, `entrypoint.sh` 158 | performs a `snapcraft` login. This enables use of `snapcraft`, e.g. by `goreleaser` 159 | to publish a `snap`. 160 | 161 | Supply `-e SNAPCRAFT_LOGIN_FILE=/other/place/.snapcraft.login` to specify an 162 | alternative mount location for the login file. See the [wiki](https://github.com/neilotoole/xcgo/wiki/Snapcraft) for more. 163 | 164 | ## Issues 165 | 166 | First, consult the [wiki](https://github.com/neilotoole/xcgo/wiki) and 167 | the [neilotoole/sqlitr](https://github.com/neilotoole/sqlitr) example project. 168 | Then open an [issue](https://github.com/neilotoole/xcgo/issues). 169 | 170 | 171 | ## FAQ 172 | 173 | See FAQ on [wiki](https://github.com/neilotoole/xcgo/wiki/FAQ). 174 | 175 | ## Related Projects 176 | 177 | Comments for related projects are as of `2020-03-14`: 178 | 179 | - [Official golang image](https://hub.docker.com/_/golang): doesn't support CGo. 180 | - [mailchain/goreleaser-xcgo](https://github.com/mailchain/goreleaser-xcgo): doesn't support `go1.14` or `snapcraft`. 181 | - [docker/golang-cross](https://github.com/docker/golang-cross): doesn't support `go1.14` or `snapcraft`. 182 | 183 | ## Acknowledgments 184 | 185 | - [mailchain/goreleaser-xcgo](https://github.com/mailchain/goreleaser-xcgo): this was the original fork point for `xcgo`. 186 | - [tpoechtrager/osxcross](https://github.com/tpoechtrager/osxcross): fundamental to macOS capabilities. 187 | - [mingw](http://www.mingw.org/): fundamental to Windows capabilities. 188 | - [goreleaser](https://goreleaser.com): core to `xcgo`'s mission. 189 | - [docker/golang-cross](https://github.com/docker/golang-cross): much gleaned from here. 190 | - [SQLite](https://www.sqlite.org/) and [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3): the perfect use case, as seen in `xcgo`'s companion example project [neilotoole/sqlitr](https://github.com/neilotoole/sqlitr). 191 | - And many others, see [sqlitr/go.mod](https://github.com/neilotoole/sqlitr/blob/master/go.mod) at a minimum. If anybody has been overlooked, please open an [issue](https://github.com/neilotoole/xcgo/issues/new). 192 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | # This section lifted from mailchain/goreleaser-xcgo 5 | # Note: you probably want to use an access token 6 | # for $DOCKER_PASSWORD rather than your real password. 7 | # See: https://docs.docker.com/docker-hub/access-tokens/ 8 | if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then 9 | echo "Login to docker using $DOCKER_USERNAME ..." 10 | if docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY; 11 | then 12 | echo "Logged into docker" 13 | echo 14 | else 15 | exit $? 16 | fi 17 | fi 18 | 19 | 20 | # Workaround for github actions when access to different repositories is needed. 21 | # Github actions provides a GITHUB_TOKEN secret that can only access the current 22 | # repository and you cannot configure it's value. 23 | # Access to different repositories is needed by brew for example. 24 | if [ -n "$GORELEASER_GITHUB_TOKEN" ] ; then 25 | export GITHUB_TOKEN=$GORELEASER_GITHUB_TOKEN 26 | fi 27 | 28 | 29 | # To use snapcraft, you must supply a snapcraft login file. 30 | # If the login file is on your host at ~/.snapcraft.login then mount 31 | # that local file to the docker image like this: 32 | # 33 | # $ docker run -it -v "${HOME}/.snapcraft.login":/.snapcraft.login neilotoole/xcgo:latest zsh 34 | # 35 | # You can specify an alternative mount location in the container like this: 36 | # $ docker run -it -v -e SNAPCRAFT_LOGIN_FILE=/my/secrets/.snapcraft.login neilotoole/xcgo:latest zsh 37 | # 38 | # Defaults to /.snapcraft.login if not specified via envar 39 | export SNAPCRAFT_LOGIN_FILE="${SNAPCRAFT_LOGIN_FILE:-/.snapcraft.login}" 40 | 41 | # If file exists and is not empty 42 | if [ -s "$SNAPCRAFT_LOGIN_FILE" ]; then 43 | echo "Login to snapcraft using $SNAPCRAFT_LOGIN_FILE ..." 44 | if snapcraft login --with "$SNAPCRAFT_LOGIN_FILE"; 45 | then 46 | echo "Logged into snapcraft" 47 | echo 48 | else 49 | exit $? 50 | fi 51 | fi 52 | 53 | exec "$@" -------------------------------------------------------------------------------- /xcgo.zsh-theme: -------------------------------------------------------------------------------- 1 | # This theme derived originally from mh theme; it's a bit of a mess 2 | # Most definitely open to improvements, with the following requirements: 3 | # - must show standard shell user thingy ($ #) as the last part of left prompt 4 | # - must show a good chunk of the current working dir 5 | # - must show git branch/dirty-status 6 | # - must show if the last return code was non-zero 7 | 8 | 9 | 10 | # features: 11 | # path is auto-shortened to ~64 characters 12 | # displays git status (if applicable in current folder) 13 | # turns username green if superuser, otherwise it is white 14 | 15 | # Special Powerline characters 16 | 17 | () { 18 | local LC_ALL="" LC_CTYPE="en_US.UTF-8" 19 | # NOTE: This segment separator character is correct. In 2012, Powerline changed 20 | # the code points they use for their special characters. This is the new code point. 21 | # If this is not working for you, you probably have an old version of the 22 | # Powerline-patched fonts installed. Download and install the new version. 23 | # Do not submit PRs to change this unless you have reviewed the Powerline code point 24 | # history and have new information. 25 | # This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of 26 | # what font the user is viewing this source code in. Do not replace the 27 | # escape sequence with a single literal character. 28 | # Do not change this! Do not make it '\u2b80'; that is the old, wrong code point. 29 | SEGMENT_SEPARATOR=$'\ue0b0' 30 | } 31 | 32 | 33 | # if superuser make the username green 34 | if [ $UID -eq 0 ]; then NCOLOR="green"; else NCOLOR="white"; fi 35 | 36 | ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}(" 37 | ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}%{$fg[yellow]%})%{$reset_color%} " 38 | ZSH_THEME_GIT_PROMPT_CLEAN="" 39 | ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[red]%}*" 40 | 41 | # LS colors, made with https://geoff.greer.fm/lscolors/ 42 | export LSCOLORS="Gxfxcxdxbxegedabagacad" 43 | export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:' 44 | 45 | 46 | 47 | function check_last_exit_code() { 48 | local LAST_EXIT_CODE=$? 49 | if [[ $LAST_EXIT_CODE -ne 0 ]]; then 50 | local EXIT_CODE_PROMPT='' 51 | EXIT_CODE_PROMPT+="%{$reset_color%}" 52 | EXIT_CODE_PROMPT+="%{$bg[red]$fg[border-circle]$fg_bold[white]%} $LAST_EXIT_CODE %{$reset_color%}" 53 | EXIT_CODE_PROMPT+="%{$reset_color%}" 54 | echo "$EXIT_CODE_PROMPT" 55 | fi 56 | } 57 | 58 | # prompt 59 | PROMPT='$(check_last_exit_code)%{$fg[cyan]%}$(hostname)%{$reset_color%}:%{$fg[blue]%}%32<...<%~%<<%{$reset_color%} $(git_prompt_info)%(!.#.$) ' 60 | --------------------------------------------------------------------------------