Generally I write my exit scripts for bash
shell in .bash_logout
. I recently started using fish
shell. The .bashrc
equivalent of fish
is located in ~/.config/fish/config.fish
but where do I find the equivalent for .bash_logout
?
Asked
Active
Viewed 1,664 times
2 Answers
4
Instead of sourcing a specific file, you define an event handler that runs when the shell exists.
From http://fishshell.com/docs/current/index.html#initialization:
If you want to run a set of commands when fish exits, use an event handler that is triggered by the exit of the shell:
function on_exit --on-process %self echo fish is now exiting end

chepner
- 497,756
- 71
- 530
- 681
-
What do you mean "not working"? What would it mean to exit upon exiting? – chepner Sep 27 '16 at 16:27
-
Sorry, that was my bad. Basically I enter into the `fish` shell from my `bash` shell. When u exit from the `fish` shell, it brings you back to the `bash` . I wanted to exit the shell prompt directly when I hit exit in `fish` shell. So I added an `exit` command within the `on_exit` function so on exit it will invoke the `exit` command and in turn I'll exit the shell. But it didn't work unfortunately. – DhiwaTdG Sep 27 '16 at 17:43
-
You can configure your terminal emulator to run `fish` directly instead of `bash`. – chepner Sep 27 '16 at 17:53
-
I'm doing this on a remote server via ssh. I added the `fish` path to `.profile` so that `fish shell` gets loaded as soon as I login and it works. Is there any way to exit the shell when I exit from the `fish shell`? – DhiwaTdG Sep 27 '16 at 19:34
-
Just run `ssh user@remotehost fish` instead of modifying your `.profile`; that runs `fish` as the remotes command, and terminates the connection as soon as the `fish` instance exits. – chepner Sep 27 '16 at 19:37
-
I tried it with 4 different commands: `ls`, `pwd`, `mkdir` & `fish`. All the 3 worked except `ssh user@remotehost fish`. – DhiwaTdG Sep 27 '16 at 19:58
-
1When you specify a command for ssh to run you normally do not get an interactive session -- specifically, no tty is allocated. You can force it with the `-t` flag: `ssh -t user@remotehost fish`. Alternatively, just ssh as normal and then do `exec fish` to replace the login shell with a fish shell. – Kurtis Rader Sep 27 '16 at 20:59
0
You may follow @chepner 's answer.
But, you can also override exit
and logout
function instead of a event listener!
function exit
echo exiting...
kill %self
end
Do the same to
logout
And, it works

Hasibul Hasn
- 318
- 5
- 16