Occasionally, emacs opens a file in shell-script[fish]
when I want it to open in shell-script[bash]
. How can I manually change the subtype of shell-script mode that I'm in?
1 Answer
What is determining whether you see shell-script[fish]
or shell-script[bash]
is probably:
The extension of the file (
*.sh
files will probably open withshell-script[bash]
, and*.fish
files will probably open withshell-script[fish]
)The starting #!-line (e.g., if the first line of the file you are opening is
#!/bin/bash
, it should start inshell-script[bash]
).
I am not sure in your case what is causing your files to open in different submodes (if you provide further detail in your question I will update my answer if necessary), but if you want to be able to manually switch between submodes as you say, you can do so with the command M-x sh-set-shell
(for me it is bound to C-c :
) and then select your desired shell from a list of completions or type it in yourself. It should also update the #!-line of whatever script you are editing.
-
4One small problem, mentioned already in this answer, is that
sh-set-shell
(when used interactively) inserts a shebang and makes the file executable. This might be undesirable for files which are meant to besource
d, not executed, by other scripts as so-called "shell libraries".– ackCommented Jul 26, 2017 at 16:06
shell-script[fish]
, what extension does it have? Can you provide any more details about what leads up to this behaviour? Also, what is the value forsh-shell-file
when you doC-h v sh-shell-file RET
? (I deleted my previous comment and am reposting it because it had a major typo but it was too late to edit it)