This is a Sublime Text 3/4 plugin to format your shell scripts using shfmt.
- Format current file, selections and scopes
- Format current file on save
- Minify current file
Obviously shfmt, you can install it in many ways:
apt install shfmt
pacman -Sy shfmt
brew install shfmt
And so on, I'm sure if you are here you already have it.
Not available on Package Control.
Git clone this repository directly in your packages folder.
Warning
The plugin name must be called shfmt
not sublime-shfmt
cd ~/.config/sublime-text/Packages
git clone https://github.com/soifou/sublime-shfmt shfmt
- Look at default values here
Preferences > Package Settings > Shfmt > Settings - Default
. - Edit your user configuration file via
Preferences > Package Settings > Shfmt > Settings - User
. - Override needed values.
Default configuration:
{
"paths": {
"linux": "",
"osx": "",
"windows": ""
},
"config": {
// Turns on autoformatting on save
"autoformat": false,
// Autoformat: if scope contains any of these, it will be auto-formatted
"autoformat_scopes": ["source.shell"],
// Autoformat: if scope contains any of these, it will never be
// auto-formatted
"autoformat_blacklisted_scopes": ["source.shell.nu"],
// Indentation: 0 for tabs (default), >0 for number of spaces
"indent": 4,
// Switch cases will be indented
"switch_case_indent": true,
// Binary operators like && and | may start a line
"binary_ops_line_start": true,
// Redirect operators will be followed by a space
"redirect_ops_space": true,
// Keep column alignment paddings
"keep_column_align_paddings": false,
// Function opening braces are placed on a separate line
"func_opening_braces_separate_line": false
}
}
If shfmt
is available in your $PATH
environment, you're already set!
Else add manually the folder where shfmt
live.
For instance, if shfmt
live in ~/.bin/shfmt
, add the following value:
"paths": {
"linux": "~/.bin",
"osx": "",
"windows": ""
},
- Format entire file:
Shfmt: Format file
- Format one or more selections:
Shfmt: Format selection(s)
- Minify entire file:
Shfmt: Minify file
Entire file:
- Linux: alt+f
- OS X: ctrl+f
- Windows: alt+f
Selection(s):
- Linux: alt+shift+f
- OS X: ctrl+shift+f
- Windows: alt+shift+f
Or add a custom key bindings using the following commands:
shfmt
shfmt_selection
shfmt_minify