From 0d8cb6690e84903162e285919b50f040d8ebaeed Mon Sep 17 00:00:00 2001 From: Riku Takeuchi Date: Sun, 26 May 2024 15:51:06 +0900 Subject: [PATCH] Refactor installation (#102) * refactor: set default WORKSPACE_REPOSITORY_URL * refactor: make if statement short * refactor: create zprofile by ansible * refactor: make git task short --- README.md | 2 +- install.sh | 26 +++++++--------- roles/cui/tasks/main.yml | 67 +++++++++++++--------------------------- 3 files changed, 34 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 550ad79..27df0e9 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ ssh-keygen -t ed25519 Run install script. ```bash -curl -fsSL https://raw.githubusercontent.com/rikuson/workspace/HEAD/install.sh | WORKSPACE_REPOSITORY_URL=git@github.com:rikuson/workspace.git && zsh - +curl -fsSL https://raw.githubusercontent.com/rikuson/workspace/HEAD/install.sh | zsh - ``` Restart terminal and run `make`. diff --git a/install.sh b/install.sh index cadc297..80a10e7 100644 --- a/install.sh +++ b/install.sh @@ -2,33 +2,29 @@ set -u +WORKSPACE_REPOSITORY_URL=${WORKSPACE_REPOSITORY_URL:-git@github.com:rikuson/workspace.git} + abort() { printf "%s\n" "$@" >&2 exit 1 } -if [[ -e $HOME/workspace ]]; then - abort '`workspace` directory already exists.' -fi -if [[ -z "$WORKSPACE_REPOSITORY_URL" ]]; then - abort '`WORKSPACE_REPOSITORY_URL` is undefined.' -fi + +[[ -e $HOME/workspace ]] && abort '`workspace` directory already exists.' # Install homebrew /bin/bash -c `curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh` -if [[ -d /opt/homebrew ]]; then - eval "$(/opt/homebrew/bin/brew shellenv)" -fi + +# Install oh-my-zsh +sh -c `curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh` + +source "$(pwd)/roles/cui/templates/.zshrc" + brew update brew upgrade -# Create bare repository +# Clone repository git clone $WORKSPACE_REPOSITORY_URL -# Install oh-my-zsh -sh -c `curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh` - # Initialize brew install ansible gem install bundler ansible_spec - -touch $HOME/.zprofile diff --git a/roles/cui/tasks/main.yml b/roles/cui/tasks/main.yml index 463c681..8718477 100644 --- a/roles/cui/tasks/main.yml +++ b/roles/cui/tasks/main.yml @@ -1,4 +1,8 @@ --- +- name: Create .zprofile + file: + path: $HOME/.zprofile + state: touch - name: Create .zshrc template: src: roles/cui/templates/.zshrc @@ -20,48 +24,21 @@ - import_tasks: ohmyzsh.yml - import_tasks: neovim.yml -# git -- name: Set git editor - git_config: - name: core.editor - scope: global - value: nvim -- name: Create .gitignore - template: - src: roles/cui/templates/.gitignore - dest: $HOME -- name: Set up global .gitignore - git_config: - name: core.excludesfile - value: ~/.gitignore - scope: global -- name: Show Japanese properly - git_config: - name: core.quotepath - value: false - scope: global -- name: Set pull rule - git_config: - name: pull.rebase - value: true - scope: global -- name: Disable pager for branch - git_config: - name: pager.branch - value: false - scope: global -- name: Disable pager for stash - git_config: - name: pager.stash - value: false - scope: global -- name: Set git email - git_config: - name: user.email - value: 'rikuson@users.noreply.github.com' - scope: global -- name: Set git user name - git_config: - name: user.name - value: 'Riku Takeuchi' - scope: global +- name: Set git global configurations + block: + - git_config: + name: "{{ item.name }}" + value: "{{ item.value }}" + scope: global + with_items: + - { name: "core.editor", value: "nvim" } + - { name: "core.excludesfile", value: "~/.gitignore" } + - { name: "core.quotepath", value: "false" } + - { name: "pull.rebase", value: "true" } + - { name: "pager.branch", value: "false" } + - { name: "pager.stash", value: "false" } + - { name: "user.email", value: "rikuson@users.noreply.github.com" } + - { name: "user.name", value: "Riku Takeuchi" } + - template: + src: roles/cui/templates/.gitignore + dest: $HOME