Commit Graph

47 Commits

Author SHA1 Message Date
Johannes Altmanninger
51a3885d8c funced: avoid interpreting special characters in function name
Commit c3374ffd0 ("Use read --tokenize instead of eval for $BROWSER &
$EDITOR") converted uses of "eval" for environment variables to use the
safer "read -at", which performs word splitting but no other expansion.

funced contained a leftover instance of "eval". Remove it in favor
of using the editor command that was already word-split.
This means that we don't accidentally evaluate the file name.

(Also "set -gx EDITOR=~/my-editor" won't work anymore because the ~
is not expanded anymore but no one has complained about that behavior
in edit_command_buffer.)

Fixes #8289
2021-09-13 19:16:41 +02:00
David Adam
ff8f26e65a funced: suggest saving functions when an editor is used 2021-08-16 21:45:23 +08:00
David Adam
8dd4c67db1 funcsave: edit the whole file containing a function
Many functions ship in files with helper functions, and it is useful to
edit those too.

Closes #391.
2021-08-16 21:45:22 +08:00
David Adam
52eff27239 funced: don't source or save unmodified files
If funced is just used to inspect a function, there's no need to write
it to storage or to reload it.
2021-08-16 21:44:43 +08:00
David Adam
911269c4a9 funcsave: avoid the edited function's path being a temporary file
As functions know where they are loaded from now, there is no point in
them being marked as loaded from a temporary file that has been removed.
Source the function via a redirect instead.
2021-08-16 21:44:43 +08:00
Fabian Homborg
18e332772d functions: Add "--no-details" flag and use it in funced
This inhibits the function path comment which is annoying in `funced`.

Fixes #7879.
2021-03-30 16:54:26 +02:00
lapingenieur
f95f12f5e7 changed 'rm' to 'command rm'
if rm is aliased to 'rm -i' then rm will ask to delete the cache file after funced edited the file which is anoying
2021-03-15 21:07:39 +01:00
Érico Rolim
31870e774a share/functions: account for the possibility of mktemp failure. 2020-11-14 15:57:42 +01:00
Johannes Altmanninger
49c5f96470 Use set -l to force use of a local variable
Bare set overwrites a global/universal variable if it exists.
2020-05-15 08:25:07 +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
Johannes Altmanninger
c3374ffd08 Use read --tokenize instead of eval for $BROWSER & $EDITOR 2019-12-03 12:19:16 +01:00
Fabian Homborg
8e60ebcd34 Revert "funced: Use variable-as-command"
This reverts commit 3253893923.

Fixes #5625.
2019-02-07 09:47:15 +01:00
Fabian Homborg
3a835ebd61 Make --help work
See #5361.
2018-11-22 12:43:35 +01:00
ridiculousfish
e09e1e8e41 Fix funced when using the built-in editor 2018-10-27 17:19:43 -07:00
Fabian Homborg
3253893923 funced: Use variable-as-command 2018-10-21 15:34:19 +02:00
Fabian Homborg
d22446f651 Let funced handle empty $EDITOR
For some weird reason we only used $editor if it wasn't empty, but
then failed to fail if it was.

This will now print an error and use fish, just like if the $EDITOR
value is invalid in any other way.

Fixes #5257.
2018-10-15 10:14:59 +02:00
Mahmoud Al-Qudsi
2a266c4d48 Update fish's only usage of read -s to use read --shell instead 2018-03-09 11:55:12 -06:00
Thom Chiovoloni
7b88187310 Add ability to autosave functions at the end of funced 2018-01-18 18:03:52 +01:00
sentriz
72173a93a7 Accept return as a valid answer to 'Edit the file again?'
Also, check for affirmative answer so a random string isn't taken as a
"yes" response.
2017-08-14 18:18:41 -07:00
Kurtis Rader
8e87d595b7 remove some uses of $IFS
This is a step towards resolving issue #4156. It replaces uses of `$IFS`
with other solutions.
2017-07-24 20:45:43 -07:00
Kurtis Rader
6ecd0bcb32 update funced to use argparse 2017-07-13 13:29:35 -07:00
Adam Byrtek
dd69ca5a81 Warn when function is not modified by the editor after calling funced (#3961)
* Check whether tmp file was modified in `funced`

* More idiomatic error messages

* Store the checksum in a local variable

* MD5 function supporting both GNU and BSD

* Use `else if` in MD5 function

* Use `string` builtin instead of `cut`
2017-04-17 17:18:02 +02: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
Fabian Homborg
d79a5a3152 Funced: Make removal safer, take two
Now we try to remove the file and then the directory, without forcing
anything, showing any (quite unexpected) error to the user, once.
2016-05-28 12:34:04 +02:00
Fabian Homborg
b9848538e3 Funced: Limit damage when removing tmpfile
This will now only forcibly remove _files_, not directories.

$tmpdir _should_ be something only we use in /tmp, but mktemp might screw up.
2016-05-24 13:55:09 +02:00
Fabian Homborg
5accc7c6c5 Fix funced's tmpfile generation on OSX
OSX mktemp... isn't great, so work around that fact.
2016-05-23 00:49:09 +02:00
Fabian Homborg
f3695b95fc Use $VISUAL before $EDITOR in funced
Closes #2268
2015-09-02 13:55:59 +02:00
Fabian Homborg
616d848fac Add .fish suffix to funced's tempfile name
This allows editors (like emacs) to pick up on the fact that it's a fish script.
2015-07-19 17:22:09 -07:00
ridiculousfish
15e095233b Allow funced to retry on error
Fixes #1371
2014-10-17 11:50:09 -07:00
Kevin Ballard
533496e43a Adopt the new type -q flag in the other functions 2014-07-13 19:11:29 -07:00
David Adam
55bc4168bf use mktemp(1) to generate temporary file names
Fix for CVE-2014-2906.

Closes a race condition in funced which would allow execution of
arbitrary code; closes a race condition in psub which would allow
alternation of the data stream.

Note that `psub -f` does not work (#1040); a fix should be committed
separately for ease of maintenance.

Closes #1437
2014-04-28 10:42:00 +08:00
ridiculousfish
825a7311ea Make funced properly handle an invalid number of arguments
Fixes https://github.com/fish-shell/fish-shell/issues/780
2013-06-08 20:29:38 -07:00
ridiculousfish
27e71c5f37 Fix funced to stop outputing an error if no EDITOR is set 2013-01-27 13:14:24 -08:00
ridiculousfish
5e9ca72731 Break up $EDITOR before passing it to type to allow it to contain flags
More work on https://github.com/fish-shell/fish-shell/issues/541
2013-01-23 18:24:49 -08:00
ridiculousfish
debfc0f712 Allow $EDITOR to be an array. Fixes https://github.com/fish-shell/fish-shell/issues/541 2013-01-23 17:14:22 -08:00
Łukasz Niemier
47df1ae40a Remove trailing whitespaces and change tabs to spaces 2012-11-18 11:23:22 +01:00
Siteshwar Vashisht
32d2d0f0d0 Minor refactoring and fixed a bug in history function 2012-07-24 04:35:37 +05:30
maxfl
ea4b37d5c5 Fixed case behaviour
* case no properly handles -h and --help flags, i.e. treats it as
  pattern
* fixed case escaping:
The following expressions now work correctly:
switch '*'
  echo '*'
  echo Match any string
end
switch '*'
  echo '\*'
  echo Match asterix
end
switch '\\'
  echo '\\\\'
  echo Match slash
end

The same for '?' sign
2012-07-05 14:17:25 -07:00
maxfl
fe26284376 Doc is updated
btw. funced completion is updated
2012-07-01 14:20:43 -07:00
maxfl
ab62fe6496 Update funced
* Editor mode is no the default
* Use -i or --interactive or -e fish to edit function in interactive
  mode
* tmpname is now created with random number added and check that file
  do not already exist
* check $TMPDIR existence and put /tmp if it does not exist
* There is an undocumented feature to use functions, started with dash.
  Introduce necessary changes to funced, functions, def_function()
  in order to make it work properly.
* Delete editor guessing. Use $EDITOR variable or -e key
2012-07-01 14:20:43 -07:00
ridiculousfish
a8bae31939 Change funced script to default to using $EDITOR if set, and to allow -e to specify a particular editor (with fish meaning the builtin editor) 2012-06-29 18:35:26 -07:00
maxfl
faea588fb8 Support editing functions starting with dot 2012-06-29 16:42:34 -07:00
maxfl
792e246262 Add emacs to 'funced -e'
The order is also changed.
2012-06-29 16:42:34 -07:00
maxfl
85f19f9b8c Add -e option to funced
New option -e or --editor allows to edit function inside external
editor, rather than in reader.
2012-06-29 16:42:34 -07:00
Grissiom
70322077d2 remove trialing spaces #2 2010-09-18 10:18:26 +08:00
liljencrantz
8c4770a26c Add boilerplate definition when using funced on undefined function
darcs-hash:20070921142954-75c98-752f389dfe4022ea3e72092bb717a60314408d41.gz
2007-09-22 00:29:54 +10:00
axel
dd48de068d Add funced function, which works like vared, but with functions
darcs-hash:20070422185539-ac50b-9080fb745cec45609e7e29971b55b96e073806e6.gz
2007-04-23 04:55:39 +10:00