brew install fish | macOS에 설치 |
apt install fish | Ubuntu에 설치 |
chsh -s /usr/local/bin/fish | 기본 셸로 설정 |
fish_config | 웹 설정 열기 |
Tab | 자동 완성 |
Ctrl+F | 자동 제안 수락 |
Alt+Right | 한 단어 수락 |
Alt+Enter | 수락 및 실행 |
Ctrl+R | 히스토리 검색 |
Alt+Up | 이전 인수 |
Alt+Down | 다음 인수 |
Alt+L | 디렉토리 목록 |
Alt+P | sudo 앞에 추가 |
Alt+E | 에디터에서 명령 편집 |
Ctrl+W | 단어 삭제 |
Ctrl+U | 줄 삭제 |
# Set variable
set name "John"
set -x PATH $PATH /usr/local/bin # Export
# Universal (persist across sessions)
set -U myvar "value"
# Global (current session)
set -g myvar "value"
# Local (current block)
set -l myvar "value"
# Erase variable
set -e myvar # Create array
set mylist one two three
# Access elements (1-indexed)
echo $mylist[1] # one
echo $mylist[-1] # three
echo $mylist[2..3] # two three
# Count
count $mylist # 3
# Append
set -a mylist four
# Prepend
set -p mylist zero $status # Exit status of last command
$argv # Command line arguments
$fish_pid # Fish process ID
$USER # Current user
$HOME # Home directory
$PWD # Current directory
$_ # Last argument of previous command if test $x -gt 10
echo "big"
else if test $x -gt 5
echo "medium"
else
echo "small"
end
# Short form
test $x -gt 10; and echo "big"; or echo "small" switch $animal
case dog
echo "bark"
case cat
echo "meow"
case '*'
echo "unknown"
end test -f file # Is file
test -d dir # Is directory
test -e path # Exists
test -r file # Readable
test -w file # Writable
test -x file # Executable
test -z "$str" # Empty string
test -n "$str" # Non-empty string
test $a -eq $b # Numbers equal
test $a = $b # Strings equal for i in 1 2 3 4 5
echo $i
end
# Range
for i in (seq 1 10)
echo $i
end
# Files
for file in *.txt
echo $file
end
# Command output
for line in (cat file.txt)
echo $line
end while test $x -lt 10
echo $x
set x (math $x + 1)
end
# Read lines
while read -la line
echo $line
end < file.txt for i in (seq 1 10)
if test $i -eq 5
continue # Skip
end
if test $i -eq 8
break # Exit loop
end
echo $i
end function greet
echo "Hello, $argv[1]!"
end
greet World # Hello, World! function ll --description "List files in detail"
ls -la $argv
end function mkcd --description "Make and cd to directory"
mkdir -p $argv[1]
cd $argv[1]
end # Run on directory change
function on_pwd_change --on-variable PWD
echo "Changed to $PWD"
end
# Run on exit
function on_exit --on-process-exit %self
echo "Goodbye!"
end # Save to file
funcsave function_name
# Edit function
funced function_name
# List functions
functions
# Show function definition
functions function_name
# Erase function
functions -e function_name # Alias (wrapper for function)
alias ll="ls -la"
alias gs="git status"
# Or as function
function ll
ls -la $argv
end
# Save alias
funcsave ll # Abbreviations expand when typed
abbr -a gco git checkout
abbr -a gst git status
abbr -a gp git push
# List abbreviations
abbr
# Remove abbreviation
abbr -e gco # Length
string length "hello" # 5
# Substring
string sub -s 1 -l 3 "hello" # hel
# Replace
string replace "old" "new" "old text" # new text
string replace -a "o" "0" "foo" # f00
string replace -r "[0-9]+" "X" "abc123" # abcX
# Split
string split "," "a,b,c" # a\nb\nc
# Join
string join "," a b c # a,b,c
# Trim
string trim " hello " # hello
# Upper/lower
string upper "hello" # HELLO
string lower "HELLO" # hello
# Match
string match "*.txt" "file.txt" # file.txt
string match -r "\d+" "abc123" # 123 math "1 + 2" # 3
math "10 / 3" # 3.333...
math "10 % 3" # 1
math "2 ^ 8" # 256
math "sqrt(16)" # 4
math "sin(0)" # 0
math "round(3.7)" # 4
math "floor(3.7)" # 3
math "ceil(3.2)" # 4
# Assign result
set result (math "1 + 2")
# Scale (decimal places)
math -s 2 "10 / 3" # 3.33 # ~/.config/fish/config.fish
# Environment variables
set -x PATH $PATH /usr/local/bin
set -x EDITOR vim
# Aliases
alias ll="ls -la"
alias gs="git status"
# Abbreviations
abbr -a gco git checkout
# Greeting
set fish_greeting "Welcome to Fish!"
# Prompt (or use fish_config)
function fish_prompt
echo -n (prompt_pwd) '> '
end # Install Fisher
curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher
# Install plugins
fisher install jorgebucaran/nvm.fish
fisher install jethrokuan/z
fisher install PatrickF1/fzf.fish
# List plugins
fisher list
# Remove plugin
fisher remove plugin-name
# Update all
fisher update fish_config | 웹 설정 열기 |
fish_config theme | 테마 선택 |
fish_config prompt | 프롬프트 선택 |
set_color --print-colors | 색상 목록 |
history | 히스토리 표시 |
history search pattern | 히스토리 검색 |
history delete --exact "command" | 특정 항목 삭제 |
history clear | 모든 히스토리 지우기 |
history merge | 히스토리 병합 |