-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern.fish
executable file
·40 lines (36 loc) · 1.07 KB
/
pattern.fish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env fish
set cmd $argv[1]
switch $cmd
case ls list ''
echo "listing all patterns..."
for line in "$(curl https://conwaylife.com/patterns/ | rg .cells)"
echo $line | string split '"' -f 2
end
exit 0
case --help -h help
echo "Usage: pattern.fish [opts] <pattern>"
echo ""
echo "opts:"
echo " -d, --download: download `<pattern>` to /tmp/<pattern>"
echo " -h, --help : show this msg"
echo ""
echo "pattern:"
echo " ls, list, [default]: list all the patterns known by conwaylife.com"
echo " <pattern> : display it inside cgol-tui"
exit 0
end
set pattern "$(string replace '.cells' '' $cmd)"
echo "pattern: '$pattern'"
set url "https://conwaylife.com/patterns/$pattern.cells"
echo "url: '$url'"
set p "/tmp/$pattern.cells"
if test -e $p
echo "already saved to '$p'"
else
echo "saving to '$p'"
curl $url -o $p
end
if test "$argv[2]" = --download; or test "$argv[2]" = -d
else
cargo r -r -- $p
end