2016-04-02 03:48:11 +00:00
|
|
|
#!/usr/bin/env fish
|
|
|
|
#
|
|
|
|
# This runs C++ files and fish scripts (*.fish) through their respective code
|
|
|
|
# formatting programs.
|
|
|
|
#
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l fish_files
|
|
|
|
set -l python_files
|
2023-06-01 16:14:12 +00:00
|
|
|
set -l rust_files
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l all no
|
2016-04-02 03:48:11 +00:00
|
|
|
|
2020-03-09 18:36:12 +00:00
|
|
|
if test "$argv[1]" = --all
|
2016-04-02 03:48:11 +00:00
|
|
|
set all yes
|
|
|
|
set -e argv[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
if set -q argv[1]
|
|
|
|
echo "Unexpected arguments: '$argv'"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if test $all = yes
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//')
|
2016-04-13 02:57:07 +00:00
|
|
|
if set -q files[1]
|
2016-07-25 00:58:56 +00:00
|
|
|
echo
|
2022-06-16 16:45:46 +00:00
|
|
|
echo 'You have uncommitted changes. Are you sure you want to restyle?'
|
|
|
|
read -P 'y/N? ' -n1 -l ans
|
2023-06-01 16:14:12 +00:00
|
|
|
if not string match -qi y -- $ans
|
2022-06-16 16:45:46 +00:00
|
|
|
exit 1
|
|
|
|
end
|
2016-04-13 02:57:07 +00:00
|
|
|
end
|
2020-12-25 06:45:08 +00:00
|
|
|
set fish_files share/**.fish
|
|
|
|
set python_files {doc_src,share,tests}/**.py
|
2023-06-01 16:14:12 +00:00
|
|
|
set rust_files fish-rust/src/**.rs
|
2016-04-02 03:48:11 +00:00
|
|
|
else
|
|
|
|
# Extract just the fish files.
|
2019-05-03 17:15:25 +00:00
|
|
|
set fish_files (string match -r '^.*\.fish$' -- $files)
|
|
|
|
set python_files (string match -r '^.*\.py$' -- $files)
|
2023-06-01 16:14:12 +00:00
|
|
|
set rust_files (string match -r '^.*\.rs$' -- $files)
|
2016-04-02 03:48:11 +00:00
|
|
|
end
|
|
|
|
|
2019-05-03 17:20:45 +00:00
|
|
|
set -l red (set_color red)
|
|
|
|
set -l green (set_color green)
|
|
|
|
set -l blue (set_color blue)
|
|
|
|
set -l normal (set_color normal)
|
|
|
|
|
2016-04-02 03:48:11 +00:00
|
|
|
# Run the fish reformatter if we have any fish files.
|
2019-05-03 17:15:25 +00:00
|
|
|
if set -q fish_files[1]
|
2016-04-02 03:48:11 +00:00
|
|
|
if not type -q fish_indent
|
|
|
|
make fish_indent
|
|
|
|
set PATH . $PATH
|
|
|
|
end
|
2019-05-03 17:20:45 +00:00
|
|
|
echo === Running "$green"fish_indent"$normal"
|
2019-05-20 19:04:51 +00:00
|
|
|
fish_indent -w -- $fish_files
|
2016-04-02 03:48:11 +00:00
|
|
|
end
|
2019-05-03 17:15:25 +00:00
|
|
|
|
|
|
|
if set -q python_files[1]
|
|
|
|
if not type -q black
|
|
|
|
echo
|
|
|
|
echo Please install "`black`" to style python
|
|
|
|
echo
|
|
|
|
else
|
2019-05-03 17:20:45 +00:00
|
|
|
echo === Running "$blue"black"$normal"
|
2019-05-03 17:15:25 +00:00
|
|
|
black $python_files
|
|
|
|
end
|
|
|
|
end
|
2023-06-01 16:14:12 +00:00
|
|
|
|
|
|
|
if set -q rust_files[1]
|
|
|
|
if not type -q rustfmt
|
|
|
|
echo
|
|
|
|
echo Please install "`rustfmt`" to style rust
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
echo === Running "$blue"rustfmt"$normal"
|
|
|
|
rustfmt $rust_files
|
|
|
|
end
|
|
|
|
end
|