📑
私のshell(途中)
構成
- zsh(macのデフォルトなので、買い替えの時にfishとお別れした)
- Nerd-font
- starship
- zshsuggestions
- fzf
NerdFontインストール
# font-hack-nerd-fontをインストール
brew install --cask font-hack-nerd-font
Starship設定
インストール
brew install starship
zshrc設定
.zshrc
に以下を貼る
.zshrc
eval "$(starship init zsh)"
諸々設定
~/.config/starship.toml
に以下のコードを貼る
設定ファイル
starship.toml
format = """
[](#9A348E)\
$os\
$username\
[](bg:#DA627D fg:#9A348E)\
$directory\
[](fg:#DA627D bg:#FCA17D)\
$git_branch\
$git_status\
[](fg:#FCA17D bg:#86BBD8)\
$c\
$elixir\
$elm\
$golang\
$gradle\
$haskell\
$java\
$julia\
$nodejs\
$nim\
$rust\
$scala\
[](fg:#86BBD8 bg:#06969A)\
$docker_context\
[](fg:#06969A bg:#33658A)\
$time\
[ ](fg:#33658A)\
"""
# Disable the blank line at the start of the prompt
# add_newline = false
# You can also replace your username with a neat symbol like or disable this
# and use the os module below
[username]
show_always = true
style_user = "bg:#9A348E"
style_root = "bg:#9A348E"
format = '[$user ]($style)'
disabled = false
# An alternative to the username module which displays a symbol that
# represents the current operating system
[os]
style = "bg:#9A348E"
disabled = true # Disabled by default
[directory]
style = "bg:#DA627D"
format = "[ $path ]($style)"
truncation_length = 3
truncation_symbol = "…/"
# Here is how you can shorten some long paths by text replacement
# similar to mapped_locations in Oh My Posh:
[directory.substitutions]
"Documents" = " "
"Downloads" = " "
"Music" = " "
コマンド補完
zsh-autosuggestionsをインストール
brew install zsh-autosuggestions
以下を.zshrcに貼る
.zshrc
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
良さげなカスタムコマンド(AIに生成してもらった)
その1: ツリーコマンド
最近、AIにプロジェクトの構成を伝える時によく使うので大事。
コード
.zshrc
# Tree command function with exclude option using -prune
# 使用例:
# tree # 現在のディレクトリを表示
# tree ./src # ./src ディレクトリを表示
# tree ./src --exclude .git # .git ディレクトリを除外
# tree ./src --exclude .git --exclude node_modules # 複数パターン除外
function tree() {
local dir="."
local exclude_patterns=()
# 引数パース
while [[ $# -gt 0 ]]; do
case "$1" in
--exclude|-e)
shift
exclude_patterns+=("$1")
;;
*)
dir="$1"
;;
esac
shift
done
# findコマンド用の引数配列を組み立てる
local find_cmd=(find "$dir")
if (( ${#exclude_patterns[@]} > 0 )); then
# 除外パターンがある場合
# ( -path "*/pattern1" -o -path "*/pattern2" ) -prune -o -print
find_cmd+=("(")
local count=0
for pattern in "${exclude_patterns[@]}"; do
if (( count > 0 )); then
find_cmd+=("-o")
fi
find_cmd+=("-path" "*/${pattern}")
((count++))
done
find_cmd+=(")" "-prune" "-o" "-print")
else
# 除外パターンがない場合は単純に-print
find_cmd+=(-print)
fi
# ツリー状に整形
"${find_cmd[@]}" | sed -e 's;[^/]*/;│ ;g;s;│ *\([^│]\);└── \1;'
}
Discussion