-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfishbash
More file actions
executable file
·39 lines (28 loc) · 872 Bytes
/
fishbash
File metadata and controls
executable file
·39 lines (28 loc) · 872 Bytes
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
#!/usr/bin/fish
# Poor man's bash -> fish converter
# Deps: perl
## TODO:
# - alias -> abbr
# - function() { ... } -> function <name>; bass <function-body> $argv; end
set bashfile $argv[1]
# HACK due to: https://github.com/fish-shell/fish-shell/issues/159
set tmpfile $bashfile.tmp
set fishfile $bashfile.fish
command cp $bashfile $tmpfile
# Remove comments
perl -pe 's/#.*$//s' -i $tmpfile
# Remove if statements
perl -0777 -pe 's/\s?if\s+.*\s+fi\s?//gs' -i $tmpfile
# Remove functions
perl -0777 -pe 's/\s?function\s+.*\s+}\s?//gs' -i $tmpfile
# Replace &&, ||
perl -0777 -pe 's/ &&/; and/gs' -i $tmpfile
perl -0777 -pe 's/ \|\|/; or/gs' -i $tmpfile
# Don't actually create aliases for now
function aliass;
echo 'setting alias: '$argv[1];
end;
perl -0777 -pe 's/alias /aliass /gs' -i $tmpfile
command cp $tmpfile $fishfile
command rm $tmpfile
echo $fishfile