This mail is a few hours old as this is a forward of a correspondance that accidentally ended up private. Ignore the slight redundancy! :)
On 10/17/07, Fernando Canizo <[EMAIL PROTECTED]> wrote: > Axel Liljencrantz wrote: > > On 10/10/07, Fernando Canizo <[EMAIL PROTECTED]> wrote: > >> I just did: > >> > >> echo 'some handy function definition' > ~/.config/fish/config.fish > >> > >> Was in a hurry and didn't noticed the '>' instead of '>>', result: > >> config gone! > > > > Ouch. I'm sorry to hear that. > > yeah, ouch, more on this at the end since clobbering files is something > I wanna discuss in deep. > > > There is no way to get the exact definition of the config file, but > > you can get a listing of all current variable definitions. > > > > Just use the 'set' command to list currently defined variables. You > > can filter the output to only show exported variable using 'set -x' > > and so on. You'll have to go over the list manually and remove things > > that you sholdn't set yourself, like PATH. > > What does this mean exactly? What's the issue with PATH? Why shouldn't > set it *myself*? I was rather unclear. Fish will inherit a PATH from it's parent, and then the internal init script of fish itself might add more elements. It is perfectly reasonable to add and remove elements of PATh, but you rarely want to redefine it wholesale. > I was messing around with PATH and I cannot add my local directories > (aka: /usr/local/bin /home/conan/bin) which contains some handy scripts > for my day to day work. I can do a 'set -l' but I don't know if that's > the right thing to do. Keep in mind that in fish, PATH is an array variable, with one element per directory. You add an element like this: set PATH $PATH /some/new/directory You can remove an element like this: set -e PATH[3] If you tried to make PATH colon-separated, like in bash, you should have gotten an error message like this one: set: Could not add component /usr/local/sbin:/some/directory to PATH. set: No such file or directory set: Did you mean 'set PATH $PATH /some/directory'? > > > That said, there aren't many situations where the config.fish is the > > easiest way to configure fish. The 'right' way to define functions is > > a two-step process: > > You have opened a new path of discovery for me with that, I was using > fish like bash, with a big configuration file full of stuff here and > there, now I have reduced it to this: > > $ cat .config/fish/config.fish > umask 077 > > if status --is-interactive > command fortune > end > > > This has a few benefits: > > * You can try out the function until you get it just right. > > * You don't accidentally delete your config file.;-) > > * All the other running shells will automatically have access to your > > new function. > > * If you update the definition of an existing function, all running > > shells will automatically reload it when needed. > > Last two totally worth the money :) :-D > > >> Q2. Is there some way to emulate this from bash: > >> > >> set -o noclobber > >> > >> that set disables '>' to overwrite existing files (and you can bypass it > >> also, so is pretty useful) > >> > >> Possible Request: if there's no way to achieve Q2, what about including > >> it in the next fish release? I think that set is in the spirit of fish. > > > > Unfortunatly, that is not currently possible. I am not a big fan of > > configuration options, so I am a bit hesitant about making the way IO > > redirections perform be configurable. > > Indeed, I forgot when I wrote it that another thing in fish philosophy > is to try to avoid configurabilititis. So: > > > I see the value in what you > > propose, but if possible I'd rather try to figure out another way to > > reach the same goal. > > First thing I tried was to make it a function, dead end there. So here > is what I've thought. > > When using > there are two possible cases relating to file creation/writing: > > 1. what to do if file doesn't exists > 2. what to do if file exists > > In the former case solution is simple: create the file and write to it. > But in case 2 there are 3 possible courses of action: > > a. overwrite the file (current default, and default for others shells too) > b. append to the file > c. refuse to write to the file > > Now 'a' is what I'm trying to avoid. 'b' can be eliminated from the > picture since we already have '>>'. 'c' is what I think should be the > default for a shell which claims to be "friendly" and to be consistent > with this sentence: "But even well designed, powerful programs sometimes > need to be updated to remove some of the old mistakes." > Dang it. No fair, using my own arguments against me. > :) > > The only thing left is that sometimes one will really want to truncate a > file. In bash this is achieved with this syntax (when noclobber is set): > > echo "nothing" >| file_to_be_truncated > > Now the syntax could be anything, it's not important, but it's important > to have a way to overcome the default. That works very well, but there is one problem. Fish allows you to redirect any file descriptor to a pipe using something like: make 2>| less The above will use the less pager to scroll through the output of make. But that clashes with the suggested syntax for clobbering files. We could chose to use something other than bash does, but when it comes to picking arbitrary squiggles for operators, I see a pretty strong benefit in making the same choices as the shell that must not be named does in order to make migration between shells easier. We could switch the pipe redirection to be 'make 2| less', though that will mean that scripts like 'cat *.foo|cut -f 2|head' will bug out. That was the original reason for chosing '2>|' instead of '2|'. > > And voilá, no configuration needed. Just sane defaults. > > I ask you kindly to give this issue a second thought. Programs should > not eliminate your precious data. We, humans, make mistakes. Right. You've convinced me that this is worth trying to change. Axel > > > -- > Fernando Canizo - http://muriandre.homelinux.org/~conan/ > ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Fish-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/fish-users
