diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..15d6b85 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2009-2023 otype + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 10d200e..4c2b108 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,48 @@ # Shell -This is my rather extensive [ZSH](http://www.zsh.org/) configuration. +#### A ZSH configurations via simple plugins. -## Requirements +
-- [ZSH](http://www.zsh.org/) -- [Oh My ZSH!](https://ohmyz.sh/) +Shell is a pluggable configuration for [ZSH](http://www.zsh.org/). Mainly focusing Linux-based systems (partially also Mac OS X), it provides helpful functions, aliases and PATH definitions for a variety of tools you might be using. + +Configurations exist for tools/SDKs like [Android SDK](https://developer.android.com/about/versions/13/setup-sdk#install-sdk), [Docker](https://www.docker.com/), [Emacs](https://www.gnu.org/software/emacs/), [Git](https://git-scm.com/), [Goenv](https://github.com/syndbg/goenv), [powerline](https://github.com/powerline/powerline), [pyenv](https://github.com/pyenv/pyenv), [rbenv](https://github.com/rbenv/rbenv), [Rust](https://www.rust-lang.org/) and [tilix](https://gnunn1.github.io/tilix-web/). -## Getting started +## Installation -1. Fork this repository, then clone it to your laptop: +#### Requirements - git clone git@github.com:otype/shell.git ~/.shell +- [ZSH](http://www.zsh.org/) +- [Oh My ZSH!](https://ohmyz.sh/) -2. Symlink ZSH configuration files: +#### Automatic installer - ln -nsf ~/.shell/zshenv ~/.zshenv - ln -nsf ~/.shell/zshrc ~/.zshrc - ln -nsf ~/.shell/zsh/ ~/.zsh - ln -nsf ~/.shell/zprofile ~/.zprofile +Via install script -3. Modify [zshrc](/zsh/zshrc) and update oh-my-zsh location and theme. +```console +curl -L https://raw.githubusercontent.com/otype/shell/main/bin/install.sh | bash +``` -4. Enable the configuration files you need: +## Enable configurations - For example, if you want to enable the homebrew config `~/.zsh/env-available/zshenv-brew`: +Once installed, all configurations can be found in `~/.zsh/env-available/`. - cd ~/.zsh/env-enabled - ln -nsf ../env-available/zshenv-brew +To enable e.g. the Android-SDK config `~/.zsh/env-available/zshenv-android` you just need to symlink the config: +```console +cd ~/.zsh/env-enabled +ln -nsf ../env-available/zshenv-android +``` -That's it! Repeat this for any other configuration and restart your terminal session. +Repeat this for any other configuration and restart your terminal session. _Note: Make sure to check each configuration for sanity and correct paths!_ diff --git a/bin/install.sh b/bin/install.sh new file mode 100644 index 0000000..d381258 --- /dev/null +++ b/bin/install.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +set -e +if [ -z "$SHELL_ROOT" ]; then + export SHELL_ROOT="${HOME}/.shell" +fi + +colorize() { + if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2" + else echo -n "$2" + fi +} + +# Checks for `.shell` file, and suggests to remove it for installing +if [ -d "${SHELL_ROOT}" ]; then + { echo + colorize 1 "WARNING" + echo ": Can not proceed with installation. Kindly remove the '${SHELL_ROOT}' directory first." + echo + } >&2 + exit 1 +fi + +failed_checkout() { + echo "Failed to git clone $1" + exit -1 +} + +checkout() { + [ -d "$2" ] || git -c advice.detachedHead=0 clone --branch "$3" --depth 1 "$1" "$2" || failed_checkout "$1" +} + +if ! command -v git 1>/dev/null 2>&1; then + echo "shell: Git is not installed, can't continue." >&2 + exit 1 +fi + +# Check ssh authentication if USE_SSH is present +if [ -n "${USE_SSH}" ]; then + if ! command -v ssh 1>/dev/null 2>&1; then + echo "shell: configuration USE_SSH found but ssh is not installed, can't continue." >&2 + exit 1 + fi + + # `ssh -T git@github.com' returns 1 on success + # See https://docs.github.com/en/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection + ssh -T git@github.com 1>/dev/null 2>&1 || EXIT_CODE=$? + if [[ ${EXIT_CODE} != 1 ]]; then + echo "shell: github ssh authentication failed." + echo + echo "In order to use the ssh connection option, you need to have an ssh key set up." + echo "Please generate an ssh key by using ssh-keygen, or follow the instructions at the following URL for more information:" + echo + echo "> https://docs.github.com/en/repositories/creating-and-managing-repositories/troubleshooting-cloning-errors#check-your-ssh-access" + echo + echo "Once you have an ssh key set up, try running the command again." + exit 1 + fi +fi + +if [ -n "${USE_SSH}" ]; then + GITHUB="git@github.com:" +else + GITHUB="https://github.com/" +fi + +checkout "${GITHUB}otype/shell.git" "${SHELL_ROOT}" "${SHELL_GIT_TAG:-main}" + +# Link all ZSH configs +echo "shell: Symlink all ZSH configurations" +ln -nsf ${SHELL_ROOT}/zshenv ~/.zshenv +ln -nsf ${SHELL_ROOT}/zshrc ~/.zshrc +ln -nsf ${SHELL_ROOT}/zsh ~/.zsh +ln -nsf ${SHELL_ROOT}/zprofile ~/.zprofile + +echo "shell: Installation finished." +echo "" +colorize 1 "Set your default shell to ZSH and restart your shell to activate the configurations"