Skip to content

Improve shell variant detection for shfmt#245

Open
rolandmas wants to merge 3 commits intolassik:masterfrom
rolandmas:shfmt-variant
Open

Improve shell variant detection for shfmt#245
rolandmas wants to merge 3 commits intolassik:masterfrom
rolandmas:shfmt-variant

Conversation

@rolandmas
Copy link

This adds a suffix to the filename passed to shfmt so it can use the default settings stored in .editorconfig even for shell scripts without an extension.

@lassik
Copy link
Owner

lassik commented Oct 20, 2023

Thanks. A better approach is to always use -ln instead of using fake filenames.

@lassik
Copy link
Owner

lassik commented Oct 20, 2023

I can write the code.

@lassik
Copy link
Owner

lassik commented Oct 20, 2023

Wait, editorconfig. Isn't it supposed to be based on filename patterns only? So if you want to use editoconfig settings for foo, you have to write a [foo] section in the .editorconfig file?

@rolandmas
Copy link
Author

Yes, correct. Which is why I needed to write a section for [.sh] and [.bash] in that file in order to save default settings for shfmt; and using -ln only doesn't cause shfmt to read these sections because it's based on filenames, hence the tweak in -filename.

(list "-filename"
(cl-case (and (eql major-mode 'sh-mode)
(boundp 'sh-shell)
(symbol-value 'sh-shell))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about binding a let variable to this value so you can use it in both then and else branches?

You can use derived-mode-p and bound-and-true-p here.

(let ((sh-shell (and (derived-mode-p '(sh-mode))
                     (bound-and-true-p sh-shell))))
  (if (buffer-file-name)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants