Sublime Text 3 shell 脚本文件格式化插件Pretty Shell

  • 内容
  • 评论
  • 相关


这几天疯狂写shell脚本,突然发现一直没有shell格式化插件,实在太影响效率了,给大家推荐这款插件,使用非常简单,保存文件的同时自动格式化,无需其他操作。

并且会及时提示语法错误位置!

安装插件

command+shift+P
输入 install 选中 install package

输入 prettyshell 选择安装插件

Package Control Messages
========================

Pretty Shell
------------

  🐚 Pretty Shell - Shell Script Formatter

      ⚠️ macOS Users
          • If your default shell have the PATH to shfmt,
              you simplu can start using this plugin.
          • If that is not the case, specify the absolute path in the settings:
              {
                  "shfmt_bin_path": "Absolute Path to shfmt"
              }

      ⚠️ *nix / Windows Users
          • You need to specify the absolute path in the settings:
              {
                  "shfmt_bin_path": "Absolute Path to shfmt"
              }

      ℹ️ Visit repository for more details:
          • https://github.com/aerobounce/Sublime-Pretty-Shell

在Mac平台插件需要依赖shfmt程序,程序通过 Homebrew 安装。Homebrew 官方源链接是越来越难了,推荐大家用阿里的镜像源。

镜像源修改方法:

#替换 brew.git 仓库地址

cd "$(brew --repo)"
git remote set-url origin git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git 

#替换 homebrew-core.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

brew update

#安装 shfmt
安装过程有提示权限错误,根据提示修改既可完成安装。

brew install shfmt
Error: The following directories are not writable by your user:
/usr/local/share/man/man8

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/share/man/man8

And make sure that your user has write permission.
  chmod u+w /usr/local/share/man/man8
sudo chown -R $(whoami) /usr/local/share/man/man8
Password:
chmod u+w /usr/local/share/man/man8
brew install shfmt
==> Downloading https://homebrew.bintray.com/bottles/shfmt-3.1.2.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/42bd98e64ae352448f09fdc2b56a71e36e3659e382338447e94d20f4d7befc
######################################################################## 100.0%
==> Pouring shfmt-3.1.2.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/shfmt/3.1.2: 6 files, 3.2MB

现在可以畅快的写脚本了~ 等不忙了,我会把这个插件也集成到便携版中。

@熊猫运维 http://xmyunwei.com

评论

0条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注