7

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?

2
  • When a file opens in 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 for sh-shell-file when you do C-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)
    – elethan
    Commented Dec 30, 2015 at 3:06
  • 1
    @elethan: There is no file extension. I'm ok with it opening in fish mode, I just want to know how to change it.
    – Dan
    Commented Dec 30, 2015 at 3:50

1 Answer 1

4

What is determining whether you see shell-script[fish] or shell-script[bash] is probably:

  1. The extension of the file (*.sh files will probably open with shell-script[bash], and *.fish files will probably open with shell-script[fish])

  2. The starting #!-line (e.g., if the first line of the file you are opening is #!/bin/bash, it should start in shell-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.

1
  • 4
    One 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 be sourced, not executed, by other scripts as so-called "shell libraries".
    – ack
    Commented Jul 26, 2017 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.