Commit graph

37 commits

Author SHA1 Message Date
Maxime Bouillot
d50e9ffff3
Add the possibility to ignore arguments in alliases (#9199)
* Replace ";" with "\n" in alias-generated functions

This can let us add a "#" in our aliases to make
them ignore additional arguments.

* Update changelog about aliases that ignore arguments

* Update test for alias.fish

This is now compliant with the aliases that can
ignore arguments.
2022-09-11 09:55:11 +02:00
Fabian Homborg
789b2010f5 Don't use a function variable in alias
This conditionally set a function variable in an unsafe way.

If you do something like

```fish
if condition
   set -f foo bar
end
```

then, if the condition was false, $foo could still use a global variable.

In this case, alias would now fail if a variable $wraps was defined globally.

This reverts most of commit 14458682d9.

The message rewording can stay, it's *fine* (tho it'll break the
translations but then we'd need a real string freeze with a
translation team for those to be worth anything anyway, soo)
2022-04-08 16:33:27 +02:00
Aaron Gyes
14458682d9 alias: little cleanup 2022-04-07 09:25:16 -07:00
Jason
80b2eb94f1 alias: print error msgs to stderr 2021-04-13 15:50:00 +02:00
Johannes Altmanninger
f20e8e5860 alias: don't add --wraps for wrappers with the same name
These aliases seem to be common, see #7389 and others.  This prevents
recursion on that example, so `alias ssh "env TERM=screen ssh"` will just
have the same completions as ssh.

Checking the last token is a heuristic which hopefully works for most
cases. Users are encouraged to use functions instead of aliases.
2020-10-10 09:24:49 +02:00
Johannes Altmanninger
03e0ec82af alias: use original body instead of escaping back and forth 2020-10-10 09:24:49 +02:00
Fabian Homborg
84b25855b0 alias: Escape the first word again
See https://stackoverflow.com/questions/63115744/alias-with-spaces-and-arguments-in-fish-3

This was broken in 115892ccd2
2020-07-27 17:19:44 +02:00
Johannes Altmanninger
be36c96028 alias.fish: unbreak listing aliases without backslashes
The description for an alias which already has escape sequences will
use backslash escapes for quoting; usually `string escape` can simply
quote it.  Use a regex that accepts either escaping style.
2020-04-18 09:35:33 +02:00
Johannes Altmanninger
9eb2b69a51 alias.fish: list aliases that are escaped, not quoted
Fixes #6910
2020-04-17 23:16:43 +02:00
Fabian Homborg
9367d4ff71 Reindent functions to remove useless quotes
This does not include checks/function.fish because that currently
includes a "; end" in a message that indent would remove, breaking the test.
2020-03-09 19:46:43 +01:00
Fabian Homborg
115892ccd2 alias: Use read --tokenize
This did some weird unescaping to try to extract the first word.

So we're now more likely to be *correct*, and the alias benchmark is
about 20% *faster*.

Call it a win-win.
2019-12-01 18:14:26 +01:00
Thom Chiovoloni
25169a44ed Add alias -s/--save, which saves the alias.
Also updates the `alias` documentation to mention the `-h`/`--help` option,
which was previously undocumented.
2018-04-09 01:08:56 +02:00
George Christou
6f1ae79a13 alias: Fix string args being parsed as options 2018-02-28 11:17:00 +01:00
ridiculousfish
973533e374 Teach alias about wrap argument injection
Update the alias function to pass arguments to 'wraps'. For example
alias gco='git checkout' now works like it ought to.
2018-02-27 14:12:44 -08:00
Kurtis Rader
f2c8e73891 add more alias unit tests
A recent regression to the `alias` command points out the need for more
unit tests of its behavior. I also decided to use it as an opportunity
to normalize the output of just `alias` to list aliases.
2017-07-15 17:36:36 -07:00
Kurtis Rader
ff4d275f22 remove left over debug statement 2017-07-14 08:18:41 -07:00
Kurtis Rader
f156bea1b7 convert alias to use argparse 2017-07-13 11:47:41 -07:00
Kurtis Rader
9dd0c47d0b harden alias against foo; bar
If the first word of the alias body ends with a semicolon we need to
strip that character, and otherwise escape the extracted command, to
ensure the subsequent function definition is valid.

Fixes #3860
2017-02-20 20:23:55 -08:00
Markus Reiter
3e35e6e488 Use string split in alias. 2017-02-10 14:09:41 +01:00
Kurtis Rader
11a60c8374 reformat all fish scripts
I hate doing this but I am tired of touching a fish script as part of
some change and having `make style` radically change it. Which makes
editing fish scripts more painful than it needs to be. It is time to do
a wholesale reformatting of these scripts to conform to the documented
style as implemented by the `fish_indent` program.
2016-11-27 21:27:22 -08:00
Aaron Gyes
960cc628b2 Don't choke defining aliases with quotes
Fixes #3510
2016-10-31 01:37:23 -07:00
Aaron Gyes
c4bd110fca List alias-created functions on alias sans args
The previous change I made here makes this not hard to do, but
kind of lame in implementation.
2016-10-28 22:31:58 -07:00
Aaron Gyes
2d46969d3e alias: identify as alias in description.
Like so:

~ $ alias foo=bar
~ $ functions foo
function foo --description 'alias foo=bar'
	bar  $argv;
end
2016-10-28 14:44:55 -07:00
Fabian Homborg
443fc66048 alias: Use source directly
The extra things `eval` does are all for code that runs
interactively. Because we just define a function, we don't need it.

This improves alias' performance by about 20-25% (0.783608s to 0.585585s
on about 500 aliases) and avoids triggering #3345.
2016-09-01 12:27:10 +02:00
Fabian Homborg
54d1d98e39 Fix aliases with whitespace
And document how that stuff works.

Fixes #2220

Also, the string stuff is cool.
2015-09-23 13:28:32 +02:00
Kevin Ballard
61ce9db4ba Make the alias built-in function work better
The new --wraps functionality was breaking aliases of the form
`alias foo='bar baz'`. That is, aliases where the body is multiple
words. Extract the first word of the body and use that instead.

Use better errors for aliases with no name or no body.
2014-08-22 11:40:59 -07:00
ridiculousfish
06400b83b1 Support for command wrapping ("aliases")
Add the --wraps option to 'complete' and 'function'. This allows a
command to (recursively) inherit the completions of a wrapped command.
Fixes #393.

When evaluating a completion, we inspect the entire "wrap chain" for a
command, i.e. we follow the sequence of wrapping until we either hit a
loop (which we silently ignore) or the end of the chain. We then
evaluate completions as if the wrapping command were substituted with
the wrapped command. Currently this only works for commands, i.e.
'complete --command gco --wraps git\ checkout' won't work (that would
seem to encroaching on abbreviations anyways). It might be useful to
show an error message for that case.

The commandline builtin reflects the commandline with the wrapped
command substituted in, so e.g. git completions (which inspect the
command line) will just work. This sort of command line munging is
also performed by 'complete -C' so it's not totally without precedent.

'alias will also now mark its generated function as wrapping the
'target.
2014-08-15 18:14:36 -07:00
Jan Kanis
2f43584727 small tweak to alias.fish: always add some prefix if in danger of infinite recursion 2013-02-19 22:58:55 +01:00
Jan Kanis
e8da9999f6 optimize 'alias', fixing bug #486. Also some minor optimizations in 'type' 2013-02-05 23:14:06 +01:00
lledey
f0000ea7d2 Re-enable alias redefinition
Fixes #494

Signed-off-by: lledey <lledey@gmail.com>
2013-01-07 15:09:32 +01:00
Jan Kanis
a4c646f75c make 'alias' check for recursive calls and insert 'command'; update docs, fix #486 2013-01-01 22:56:08 +01:00
Evan Jones
1fa0c4d4d3 alias: Support seds that don't support \n in replacements.
This makes the alias command work on Mac OS X.
2012-06-17 15:01:04 -07:00
Siteshwar Vashisht
9b781c4c06 Modified alias.fish to show help message when executed with 0 arguments 2012-06-13 00:29:05 +05:30
axel
a03a4d1ba3 Add newline to error message in alias.fish. This problem was reported by flixil.
darcs-hash:20070412115221-ac50b-0ff23d6e2158522d10c7e799dc9f1594112f1869.gz
2007-04-12 21:52:21 +10:00
axel
7492b6cdb3 Make all descriptions for function calls use the implicit translation from the previous patch instead of explicitly using N_
darcs-hash:20070116012918-ac50b-c1c0df64333ad910ca81dbc86ad193ece6680722.gz
2007-01-16 11:29:18 +10:00
axel
1b71f91a01 Update documentation display code to run roff on the client system instead of pregenerating documentation and compiling it into program binaries
darcs-hash:20061117162438-ac50b-5c4c7f0bd8bf53a16e16ecfead9569e642b7160f.gz
2006-11-18 02:24:38 +10:00
axel
9959e53985 Add alias function. Thanks to Tassilo Horn for pointing out that it was missing.
darcs-hash:20061107205539-ac50b-0053f828d40be5bcb088cdb8d669c239c201b433.gz
2006-11-08 06:55:39 +10:00