Skip to content

Instantly share code, notes, and snippets.

@StefanoBelli
Last active December 29, 2016 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanoBelli/60a4705284360e52efb0204d12ce8d3a to your computer and use it in GitHub Desktop.
Save StefanoBelli/60a4705284360e52efb0204d12ce8d3a to your computer and use it in GitHub Desktop.
Uncrustify your source code very fast with this fish shell function
function uncrustyme
set UCM_CFG $HOME/.uncrustyme.cfg
set cnt 1
set total 0
set rc (ls | grep "\.$UCM_EXT\$")
if test -f $UCM_CFG
printf " \033[32m==>\033[0m Found configuration file: $UCM_CFG\n"
else
printf " \033[31m==>\033[0m Cannot find configuration file: $UCM_CFG\n"
return 1
end
printf " \033[34m==>\033[0m Counting objects..."
for i in $rc
set total (math $total + 1)
end
echo
if math "$total == 0" >/dev/null
printf " \033[31m==>\033[0m Cannot find any match with \".$UCM_EXT\" \n"
return 2
end
for i in $rc
printf " \033[33m==>\033[0m [$cnt/$total] Doing work on $i\n"
uncrustify -c $UCM_CFG -f $i -o $i.$UCM_EXT 2>/dev/null >/dev/null ;and printf " \033[32m==>\033[0m OK!\n" ;or printf " \033[31m==>\033[0m FAILED!\n"
mv $i.$UCM_EXT $i
set cnt (math $cnt + 1)
end
end
@StefanoBelli
Copy link
Author

Example

You have to get your uncrustify config in $HOME/.uncrustyme.cfg

Get and customize it here: http://uncrustify.sourceforge.net/default.cfg

$ set -x UCM_EXT cpp # set your source code extension
$ uncrustyme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment