8/28/2023 0 Comments Fish shell aliases![]() A simple solution is to print the current working directory followed by a greater-than sign: function fish_prompt ![]() While the prompt defaults to showing the hostname and the current working directory, it can be changed to anything. Instead, it executes the fish_prompt function, which can be used to print a prompt. You may notice that fish doesn’t provide a way to customize the command prompt via the PS1 variable. But there’s one caveat coming from Z Shell or Bash. With the greeting modified, it would be a great time to modify fish’s prompt too. Anything inside the fish_greeting function will now be shown in a new session. One easy way to override or suppress it is by adding a fish_greeting.fish file to your functions directory. This is presented whenever you start a new shell session. While the alias command still exists in fish, it’s just as easy to create a function file as it is to alias it in the fish config.Īn example of a quick override is the fish_greeting. The functions directory adds a central location to list wrapped commands. They’re automatically loaded to the list of functions you can access from the fish shell, so there’s no need to add the directory to the path yourself.Īliases are available in fish, but they’re not recommended for creating functions. For the first issue, all functions live in your home directory under ~/.config/fish/functions. ![]() The fish shell does away with both of these problems. I struggled to remember whether a command was aliased in my. Mine was cluttered with scripts that weren’t really binaries. If you’re like me, you have a bin directory that acts as a catch-all in your $HOME directory. FunctionsĪ fish function is a list of commands, which may optionally take arguments.įunctions are by far the best reason to try out the fish shell. The separation of components into smaller, focused routines is a job that developers do every day. The unique part of the fish shell is the way it uses functions to decrease the reliance on monolithic config files. ![]() (If you’re interested in switching to fish shell, my colleague John can show you how to set it up and use its coolest features.) However, fish shell acts as a highly configurable alternative to other shells. While text editors and IDEs come with config files and community standards for customizations, Unix-like shells can feel barren in comparison. Fish shell does good things for me out of the box.Developers use a lot of customizable tools, and it’s easy to reason through most of them. I might have played with zsh for a month some years ago, it never gave me much that bash didn't and only bought irksome incompatibilities. If I touch junk.txt I don't want to have to follow that with a config file edit to assure the system I want it there next time, I just expect it to persist. When I decide I want to make an environment variable permanent I just set -xU, if I don't want the permanence set -x. The fish/functions directory behaves like that. So there is now a directory /etc/apt// into which you drop one file for this and a separate file for that. The problem of crufty config files has plagued unix configuration for a while: adding this modification to /etc/apt/sources.list and then adding that modification makes it hard to excise this. Oh, need SOME_ENV_VAR? Well, first figure out if it is a login configuration or a per-shell item, then edit the proper script, then log back in again since you can't simply source the file you changed because it has non-idempotent declarations. The biggest problem with configuration files is they tend to clutter up easily. However, with an interactive shell, I have bought into "command line shell for the 90s" happily. Talk about old school, I still script for sh because bash is too modern with too many frills. I tweaked it so all my fish functions are available as commands to all the processus in my system. You don't forget the original command line when using them :) It is again listed as a function/command when you auto-complete in fish but it is more didactic than alias. Well you get my point.Ībbreviations are nice too. Like the coherent syntax (end for ending everything). That and command substitution with parenthesis. My fish is heavily customized but my config.fish file is empty. If yes just enter a save command and you're done. Fiddle, make it work and then decide if you want it (it being a variable or a function) permanent or not. ![]() In other shells you fiddle with something, then when it's working you need to add it to a file somewhere that will do it at boot.įish does this for you. Same for aliases (that are in fact functions created in a simpler way when this is just wrapping a command) that persist reboots when saved. The functions that are funcsaved will survive a reboot. Variables that are set Universal don't need to be set again. Fish gives you a way of defining what you need and at the same time choosing how permanent you want it to be. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |