├── .bashrc ├── .gitconfig ├── .tigrc ├── LICENSE.txt ├── README.md └── install.sh /.bashrc: -------------------------------------------------------------------------------- 1 | clipboard_copy() { 2 | clip.exe 3 | } 4 | 5 | clipboard_paste() { 6 | powershell.exe -command get-clipboard 7 | } 8 | 9 | # Wrap given text with specified color's escape sequence. 10 | # 11 | # ## Arguments 12 | # 13 | # 1. preserved color name (e.g. 'yellow') 14 | # 2. wrapped text (e.g. 'Lorem ipsum dolor sit amet') 15 | color() { 16 | local clear='\001\033[00m\002' 17 | local code 18 | 19 | case "${1}" in 20 | red) 21 | code='\001\033[01;31m\002' 22 | ;; 23 | yellow) 24 | code='\001\033[01;33m\002' 25 | ;; 26 | blue) 27 | code='\001\033[01;34m\002' 28 | ;; 29 | purple) 30 | code='\001\033[01;35m\002' 31 | ;; 32 | esac 33 | 34 | echo -e "${code}${2}${clear}" 35 | } 36 | 37 | ghq_fuzzy_select() { 38 | ghq list --full-path | peco 39 | } 40 | 41 | ghq_fuzzy_switch() { 42 | cd $(ghq_fuzzy_select) 43 | } 44 | 45 | git_branch_create_feature() { 46 | git switch --create "$1" 47 | } 48 | 49 | git_branch_current() { 50 | git rev-parse --abbrev-ref HEAD 2> /dev/null 51 | } 52 | 53 | git_branch_delete_selected() { 54 | git_branch_list | peco | xargs git branch --delete --force 2> /dev/null 55 | } 56 | 57 | git_branch_delete_merged() { 58 | git branch --merged | grep -v \* | xargs git branch --delete 2> /dev/null 59 | } 60 | 61 | git_branch_list() { 62 | git branch --format '%(refname:lstrip=2)' 63 | } 64 | 65 | git_commit_with_arguments_message() { 66 | git commit --allow-empty --message "$*" 67 | } 68 | 69 | git_fuzzy_branch_select() { 70 | git_branch_list | peco 71 | } 72 | 73 | git_fuzzy_branch_switch() { 74 | git_fuzzy_branch_select | xargs git checkout 75 | } 76 | 77 | git_fuzzy_stage_files() { 78 | git status --porcelain | sed -e 's/^...//' | peco | xargs git add 79 | } 80 | 81 | git_replace() { 82 | git grep --files-with-matches -E -- "${1}" | xargs sed -i -r "s;${1};${2};g" 83 | } 84 | 85 | prompt() { 86 | if [ $? -eq 0 ]; then 87 | local symbol_color_name='yellow' 88 | else 89 | local symbol_color_name='red' 90 | fi 91 | cat <<-SHELL 92 | $(color 'blue' ${PWD}) $(color 'purple' $(git_branch_current)) 93 | $(color ${symbol_color_name} '$') $() 94 | SHELL 95 | } 96 | 97 | retry_previous_command_with_prompt() { 98 | previous_command=$(fc -ln -2 -2 | awk '{$1=$1}1') 99 | echo "$ ${previous_command}" 100 | $previous_command 101 | } 102 | 103 | tmux_create_new_session_from_pwd() { 104 | tmux new-session -s $(tmux_session_name_from_pwd) 105 | } 106 | 107 | tmux_fuzzy_attach_session() { 108 | tmux attach-session -t $(tmux_fuzzy_select_session) 109 | } 110 | 111 | tmux_fuzzy_select_session() { 112 | tmux_list_session | peco 113 | } 114 | 115 | tmux_list_session() { 116 | tmux list-session -F "#{session_name}" 117 | } 118 | 119 | tmux_session_name_from_pwd() { 120 | basename ${PWD} | sed 's/\.//g' 121 | } 122 | 123 | export PS1='$(prompt)' 124 | 125 | alias cb='code ~/.bashrc' 126 | alias co='clipboard_copy' 127 | alias dc='docker-compose' 128 | alias dk='docker ps --quiet | xargs --no-run-if-empty docker kill' 129 | alias ga='git_fuzzy_stage_files; git status --short' 130 | alias gaa='git add --all' 131 | alias gb='git branch' 132 | alias gc='git_fuzzy_branch_switch' 133 | alias gco='git checkout' 134 | alias gd='git diff' 135 | alias gf='git_branch_create_feature' 136 | alias gg='git grep' 137 | alias gl='git pull' 138 | alias gm='git_commit_with_arguments_message' 139 | alias gpf='git push --force' 140 | alias gr='git_replace' 141 | alias grc='git rebase --continue' 142 | alias gs='git status --short' 143 | alias gx='git_branch_delete_selected' 144 | alias gz='git_branch_delete_merged' 145 | alias pa='clipboard_paste' 146 | alias pd='gh pr create --draft' 147 | alias po='gh repo view --web' 148 | alias pr='gh pr view -w || gh pr create -w' 149 | alias prc='gh pr create --fill' 150 | alias prcd='prc --draft' 151 | alias qe='ghq_fuzzy_switch' 152 | alias qf='ghq get -p' 153 | alias rc='retry_previous_command_with_prompt | clipboard_copy' 154 | alias sb='source ~/.bashrc' 155 | alias ta='tmux_fuzzy_attach_session' 156 | alias tl='tmux_list_session' 157 | alias tn='tmux_create_new_session_from_pwd' 158 | 159 | export EDITOR="code --wait" 160 | -------------------------------------------------------------------------------- /.gitconfig: -------------------------------------------------------------------------------- 1 | [user] 2 | name = r7kamura 3 | email = r7kamura@gmail.com 4 | 5 | [github] 6 | user = r7kamura 7 | 8 | [pull] 9 | rebase = true 10 | 11 | [push] 12 | default = current 13 | 14 | [core] 15 | quotepath = false 16 | 17 | [branch] 18 | autosetuprebase = always 19 | [advice] 20 | skippedCherryPicks = false 21 | [init] 22 | defaultBranch = main 23 | -------------------------------------------------------------------------------- /.tigrc: -------------------------------------------------------------------------------- 1 | bind main o !gh browse -- %(commit) 2 | bind diff o !gh browse -- %(commit) 3 | bind log o !gh browse -- %(commit) 4 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ryo Nakamura 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 | # dotfiles 2 | 3 | A chain of configurations for my workstation. 4 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | 4 | dotfiles_directory="$(cd "$(dirname "$0")"; pwd -P)" 5 | ln -fs ${dotfiles_directory}/.bashrc ~/.bashrc 6 | ln -fs ${dotfiles_directory}/.gitconfig ~/.gitconfig 7 | ln -fs ${dotfiles_directory}/.tigrc ~/.tigrc 8 | source ~/.bashrc 9 | 10 | sudo apt-get update 11 | sudo apt-get install --yes \ 12 | curl \ 13 | peco \ 14 | ssh \ 15 | tig 16 | 17 | (type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \ 18 | && sudo mkdir -p -m 755 /etc/apt/keyrings \ 19 | && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \ 20 | && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \ 21 | && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ 22 | && sudo apt update \ 23 | && sudo apt install gh -y 24 | --------------------------------------------------------------------------------