Manage repositories easily with ghq and peco (WSL2 or Mac).
投稿日: 2024/06/25
更新日: 2024/07/02
This article is a translation of the following article.
I am setting up my environment using WSL2, but it should be the same on Mac as well.
Install zsh
Please skip if not necessary.
$ sudo apt install zsh $ zsh --version zsh 5.8 (x86_64-ubuntu-linux-gnu)
Change the default to zsh.
$ echo $SHELL /bin/bash $ chsh -s $(which zsh)
When you restart the terminal, it will be displayed as follows. You will be asked what to do because files such as .zshrc
are missing. This time, we will create an empty .zshrc
, so enter 0
.
This is the Z Shell configuration function for new users, zsh-newuser-install. You are seeing this message because you have no zsh startup files (the files .zshenv, .zprofile, .zshrc, .zlogin in the directory ~). This function can help you with a few settings that should make your use of the shell easier. You can: (q) Quit and do nothing. The function will be run again next time. (0) Exit, creating the file ~/.zshrc containing just a comment. That will prevent this function being run again. (1) Continue to the main menu. (2) Populate your ~/.zshrc with the configuration recommended by the system administrator and exit (you will need to edit the file by hand, if so desired). --- Type one of the keys in parentheses ---
Check with the following command.
% echo $SHELL /usr/bin/zsh
Installing Homebrew
Please skip if already installed.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once completed, the Next Step will be displayed kindly, so please follow it.
==> Next steps: - Run these two commands in your terminal to add Homebrew to your PATH: echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/wsl_yosi/.zprofile eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" - Install Homebrew's dependencies if you have sudo access: sudo apt-get install build-essential For more information, see: https://docs.brew.sh/Homebrew-on-Linux - We recommend that you install GCC: brew install gcc - Run brew help to get started - Further documentation: https://docs.brew.sh
$ echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.zshrc $ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" $ source ~/.zshrc $ brew --version Homebrew 3.5.1 Homebrew/homebrew-core (git revision 0712e880ba1; last commit 2022-06-12)
I will also install the compiler while I'm at it.
$ sudo apt-get install build-essential
Installing ghq and peco
Install ghq
and peco
using Homebrew.
$ brew install go $ brew install ghq $ git config --global ghq.root '~/projects' $ brew install peco
Open ~/.zshrc
with vim
or a text editor and add the following lines. This sets up the shortcut key Ctrl
+ ]
to be usable.
function peco-projects () { local selected_dir=$(ghq list -p | peco --query "$LBUFFER") if [ -n "$selected_dir" ]; then BUFFER="cd ${selected_dir}" zle accept-line fi zle clear-screen } zle -N peco-projects bindkey '^]' peco-projects
$ source ~/.zshrc
How to use ghq and peco
Clone with ghq
ghq get [email protected]:yosipy/one_time_password.git
Display List of Repositories
Pressing Ctrl
+ ]
will display it.
You can select it by pressing Enter after searching for it with character input, or by using the arrow keys and Enter.