Skip to content

Instantly share code, notes, and snippets.

@marshallvaughn
Last active May 17, 2023 06:48
Show Gist options
  • Save marshallvaughn/b60d40b30e5de18f1527f5da70364af3 to your computer and use it in GitHub Desktop.
Save marshallvaughn/b60d40b30e5de18f1527f5da70364af3 to your computer and use it in GitHub Desktop.
Fish cheatsheet
# Get only the name of the current directory
basename $PWD
# ~
# Set an array var
set _shows 'The Office' 'It\'s Always Sunny in Philadelphia'
# For loop
for _show in $_shows
echo "I love $_show!"
end
# I love The Office!
# I love It's Always Sunny in Philadelphia!
# For loops work inline too!
for _show in $_shows; echo "I love $_show!"; end
# I love The Office!
# I love It's Always Sunny in Philadelphia!
# Iterate on a short list
for _n in {1,2,'three',"four"}; echo $_n; end
# 1
# 2
# three
# four
# List some numbers
seq -w 1 3
# 1
# 2
# 3
# Numbers will pad automagically
seq -w 1 10
# 01
# 02
# 03
# 04
# 05
# 06
# 07
# 08
# 09
# 10
# Loop a statement forever
printf "You sound like "; while true; echo "a broken record." && sleep 1; end
# You sound like
# a broken record.
# a broken record.
# a broken record.
# ...
# Check whether any args were given, and they're not blank
if set -q argv[1]; and test -n argv[1]
echo "yeahp"
else
echo "it's gonna be a no from me, dog"
end
# $ run
# it's gonna be a no from me, dog
# $ run with some text
# yeahp
# Get lines only found in the first file
comm -23 file1 file2
# Get lines only found in the second file
comm -13 file1 file2
# Get common lines to both files
comm -12 file1 file2
# Get common lines from stdin and file1
cat file1 | comm -12 - file2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment