Score:1

Can't Create a Permanent Alias In Fish Shell

es flag

I'm trying to create a permanent alias. I've created one long ago, but I don't remember if I did anything differently than what I'm doing now. Be as it may, it isn't working!

I start by opening the terminal and type

nano ~/.bashrc

Then I scroll to the end (just in case, I don't know) and type

alias pd="pwd"

(this is not the alias I'm actually creating).

When I close and save the bashrc file I type pd and the command isn't recognized. Plus, when I type the alias command to see my aliases, the pd doesn't show!

However, If I type bash (I'm using the fish shell) the terminal goes back to normal (sorry for my high-tech lingo) and the aliases are created and I can use them!

Is there anything I'm doing wrong?

Thanks!

Will avatar
id flag
I see you’ve found a way to sort it. However, I suspect your original method (in the question) will work - but only if you tell the shell to re-read your .bashrc file: once you’ve saved your edited file, type . .bashrc (note the leading . followed by space) - and it should work. Alternatively close and reopen the terminal.
es flag
@Will I didn't type that, but I closed and reopened the terminal. I even restarted the computer xD Thanks anyway!
Will avatar
id flag
Might be interesting to see if forcing a .bashrc read as above would work - create a temporary alias in .bashrc and try forcing the read then see if it works - just for interest / next time you need to do this. I don’t use fish so may not be good advice I gave!
es flag
@Will I wrote it as you said (just typed . .bashrc on the terminal) and got back this: .bashrc (line 6): 'case' builtin not inside of switch block case $- in ^ from sourcing file .bashrc .: Error while reading file “.bashrc” I don't know what this means.
terdon avatar
cn flag
Fish and bash are both shells, they are the same kind of thing, but they are not the same shell. `.bashrc` is the configuration file for the bash shell, anything you do there won't affect the fish shell. If you want to do things to fish, you need to modify _its_ configuration file, not bash's! This is why nothing works for you until you run `bash`: running `bash` starts a new bash shell, and since you have modified bash's configuration file, the changes will take effect now that you run bash.
es flag
@terdon it makes sense! Is there a way to do these modifications generally, I mean, for any shell?
terdon avatar
cn flag
@RichHardFineMan no. They are completely independent things. Basically, it's like filling up the tires on one car and expecting that to affect the tires of another car. Yes, they are both cars, but work done on one doesn't affect the other. The same goes for shells: each is a completely independent program. Now, some shells do share certain files like `~/.profile`, but fish isn't one of them and you cannot generalize, it will always depend on the specific shells you are using. For one thing, as is the case with bash and fish, the format of the conf files can be completely different.
es flag
Ok, got it. Thank you so much!
Score:1
es flag

Basically, in the fish shell, you type

alias pd="pwd"

which creates a temporary alias. To turn it into a permanent one you do

funcsave pd
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.