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?

Dan
  • 275
  • 2
  • 8
  • 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 Dec 30 '15 at 03: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 Dec 30 '15 at 03:50

1 Answers1

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.

elethan
  • 4,755
  • 3
  • 29
  • 56
  • 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 `source`d, not executed, by other scripts as so-called "shell libraries". – ack Jul 26 '17 at 16:06