Last active
January 22, 2017 08:35
-
-
Save ryotako/48406902bf5653c622e842e7c83a9da6 to your computer and use it in GitHub Desktop.
fishのビルトインコマンドだけでegzactを書く練習
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addb | |
while read -l line | |
echo $line | |
end | |
if count $argv >/dev/null | |
echo $argv[1] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addl | |
if count $argv >/dev/null | |
while read -l line | |
echo $argv[1]$line | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addr | |
if count $argv >/dev/null | |
while read -l line | |
echo $line$argv[1] | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addt | |
if count $argv >/dev/null | |
echo $argv[1] | |
end | |
while read -l line | |
echo $line | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function comb | |
function __comb | |
set -l length $argv[1] | |
set -l i $argv[1] | |
read -al line | |
while test $i -le (count $line) | |
if test $length -le 1 | |
echo $line[$i] | |
else | |
set -l i_ (math $i - 1) | |
for former in (echo $line[1..$i_] | __comb (math $argv[1] - 1)) | |
echo $former $line[$i] | |
end | |
end | |
set -l i (math $i + 1) | |
end | |
end | |
while read -al line | |
if test "$argv[1]" -gt (count $line) | |
echo $line | __comb (count $line) | |
else if test "$argv[1]" -gt 0 | |
echo $line | __comb $argv[1] | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function conv | |
set -l buf | |
while read -al line | |
set buf $buf $line | |
end | |
# parse an argument | |
set -l step | |
if test "$argv[1]" -gt 1 | |
set step $argv[1] | |
else | |
set step 1 | |
end | |
set -l total (math (count $buf) - $step + 1) | |
set -l fst 1 | |
while test "$fst" -le "$total" | |
set lst (math $fst + $step -1) | |
echo $buf[$fst..$lst] | |
set fst (math $fst + 1) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function crops | |
while read -l line | |
set -l length (string length $line) | |
set -l start 1 | |
set -l buf | |
while test $start -le $length | |
set -l i 1 | |
while test $i -le (math $length - $start + 1) | |
set -l sub (string sub -s $start -l $i $line) | |
if not contains $sub $buf; and string match -qr "^$argv[1]\$" "$sub" | |
set buf $buf $sub | |
end | |
set i (math $i + 1) | |
end | |
set start (math $start + 1) | |
end | |
for s in $buf | |
echo $s | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cycle | |
while read -al line | |
set -l i 1 | |
while test $i -le (count $line) | |
if test $i -eq 1 | |
echo $line | |
else | |
set -l i_ (math $i - 1) | |
echo $line[$i..-1] $line[1..$i_] | |
end | |
set i (math $i + 1) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dropl | |
while read -al line | |
if test "$argv[1]" -gt 0 | |
if test "$argv[1]" -lt (count $line) | |
set -l n (math $argv[1] + 1) | |
echo $line[$n..-1] | |
else | |
echo | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dropr | |
while read -al line | |
if test "$argv[1]" -gt 0 | |
if test "$argv[1]" -lt (count $line) | |
set -l n (math (count $line) - $argv[1]) | |
echo $line[1..$n] | |
else | |
echo | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dupl | |
while read -l line | |
if test "$argv[1]" -gt 0 | |
echo $line | |
echo $line | dupl (math "$argv[1]" - 1) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flat | |
set -l buf | |
set -l i 0 | |
while read -al line | |
set buf $buf $line | |
set i (math $i+1) | |
if test "$i" -eq "$argv[1]" | |
echo $buf | |
set buf | |
set i 0 | |
end | |
end | |
if test $i -ne 0 | |
echo $buf | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mirror | |
while read -al line | |
echo $line[-1..1] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nestl | |
function __nestl | |
read -al line | |
if test (count $line) -lt 2 | |
string replace \* " $line[-1] " "$argv[1]" | |
else | |
set -l repl (echo $line[1..-2] | __nestl $argv) | |
string replace \* " $repl $line[-1] " "$argv[1]" | |
end | |
end | |
while read -l line | |
echo $line | __nestl $argv | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nestr | |
function __nestr | |
read -al line | |
if test (count $line) -lt 2 | |
string replace \* " $line[1] " "$argv[1]" | |
else | |
set -l repl (echo $line[2..-1] | __nestr $argv) | |
string replace \* " $line[1] $repl " "$argv[1]" | |
end | |
end | |
while read -l line | |
echo $line | __nestr $argv | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function obrev | |
while read -al line | |
echo "$line[1..-1]" | |
echo "$line[-1..1]" | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function perm | |
function __perm | |
read -al line | |
if test "$argv[1]" -eq 1 | |
for word in $line | |
echo $word | |
end | |
else if test "$argv[1]" -gt 1 | |
set -l i 1 | |
while test $i -le (count $line) | |
if test (count $line) -lt 2 | |
echo $line[$i] | |
else | |
set -l rest | |
if test $i -eq 1 | |
set rest $line[2..-1] | |
else if test $i -eq (count $line) | |
set rest $line[1..-2] | |
else | |
set -l i_ (math $i - 1) | |
set -l i__ (math $i + 1) | |
set rest $line[1..$i_] $line[$i__..-1] | |
end | |
for latter in (echo $rest | __perm (math "$argv[1]" - 1)) | |
echo $line[$i] $latter | |
end | |
end | |
set i (math $i + 1) | |
end | |
end | |
end | |
while read -l line | |
echo $line | __perm "$argv[1]" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function slit | |
set -l buf | |
while read -al line | |
set buf $buf $line | |
end | |
# parse an argument | |
set -l rows | |
if test "$argv[1]" -gt 0 | |
set rows $argv[1] | |
else | |
set rows (count $buf) | |
end | |
set -l step (math (count $buf) / $rows) | |
set -l mod (math (count $buf) \% $rows) | |
set -l fst 1 | |
set -l loop 1 | |
while true | |
set -l lst (math $fst + $step -1) | |
if test "$loop" -le "$mod" | |
set lst (math $lst + 1) | |
end | |
if test "$lst" -ge (count $buf) | |
echo $buf[$fst..-1] | |
break | |
end | |
echo $buf[$fst..$lst] | |
set fst (math $lst + 1) | |
set loop (math $loop + 1) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stairl | |
while read -al line | |
set -l i 1 | |
while test $i -le (count $line) | |
echo $line[1..$i] | |
set i (math $i + 1) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stairr | |
while read -al line | |
set -l i -1 | |
while test (math 0 - $i) -le (count $line) | |
echo $line[$i..-1] | |
set i (math $i - 1) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sublist | |
while read -al line | |
set -l lst 1 | |
while test $lst -le (count $line) | |
set -l fst 1 | |
while test $fst -le $lst | |
echo $line[$fst..$lst] | |
set fst (math $fst + 1) | |
end | |
set lst (math $lst + 1) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function subset | |
function __subset | |
set -l length $argv[1] | |
set -l i $argv[1] | |
read -al line | |
while test $i -le (count $line) | |
if test $length -le 1 | |
echo $line[$i] | |
else | |
set -l i_ (math $i - 1) | |
for former in (echo $line[1..$i_] | __subset (math $argv[1] - 1)) | |
echo $former $line[$i] | |
end | |
end | |
set -l i (math $i + 1) | |
end | |
end | |
while read -al line | |
set -l i 1 | |
while test $i -le (count $line) | |
echo $line | __subset $i | |
set i (math $i + 1) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function takel | |
while read -al line | |
if test "$argv[1]" -gt 0 | |
if test "$argv[1]" -gt (count $line) | |
echo $line | |
else | |
echo $line[1..$argv[1]] | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function takelx | |
while read -al line | |
set -l buf | |
set -l matched 0 | |
if test -z "$argv[1]" | |
return 0 | |
end | |
for word in $line | |
set buf $buf $word | |
if string match -qr "$argv[1]" $word | |
set matched 1 | |
break | |
end | |
end | |
if test $matched -eq 1 | |
echo $buf | |
else | |
echo | |
end | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function taker | |
while read -al line | |
if test "$argv[1]" -gt 0 | |
if test "$argv[1]" -gt (count $line) | |
echo $line | |
else | |
set -l n -$argv[1] | |
echo $line[$n..-1] | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function takerx | |
while read -al line | |
set -l buf | |
set -l matched 0 | |
if test -z "$argv[1]" | |
return 0 | |
end | |
for word in $line[-1..1] | |
set buf $word $buf | |
if string match -qr "$argv[1]" $word | |
set matched 1 | |
break | |
end | |
end | |
if test $matched -eq 1 | |
echo $buf | |
else | |
echo | |
end | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wrap | |
while read -al line | |
set -l buf | |
for word in $line | |
set buf $buf (string replace \* $word "$argv[1]") | |
end | |
echo $buf | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function zniq | |
while read -al line | |
set -l buf | |
for word in $line | |
if not contains $word $buf | |
set buf $buf $word | |
end | |
end | |
echo $buf | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function zrep | |
if test -z "$argv[1]" | |
return 0 | |
end | |
while read -al line | |
set -l buf | |
for word in $line | |
if string match -qr $argv[1] $word | |
set buf $buf $word | |
end | |
end | |
echo $buf | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment