diff options
author | Kurtis Rader <krader@skepticism.us> | 2016-05-08 15:57:56 -0700 |
---|---|---|
committer | Kurtis Rader <krader@skepticism.us> | 2016-05-14 20:38:32 -0700 |
commit | 51468b764689e7d724a87e6c2b8cdb4e599a3604 (patch) | |
tree | 75fe13dbad791e0d143a3610bfe7ed7d0136ad38 /share/functions/history.fish | |
parent | ff1d651415a2752e82ec417294f9bdf8c234c10f (diff) |
add `function --shadow-builtin` flag
It's currently too easy for someone to bork their shell by doing something
like `function test; return 0; end`. That's obviously a silly, contrived,
example but the point is that novice users who learn about functions are
prone to do something like that without realizing it will bork the shell. Even
expert users who know about the `test` builtin might forget that, say, `pwd`
is a builtin.
This change adds a `--shadow-builtin` flag that must be specified to
indicate you know what you're doing.
Fixes #3000
Diffstat (limited to 'share/functions/history.fish')
-rw-r--r-- | share/functions/history.fish | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/share/functions/history.fish b/share/functions/history.fish index 0de39e30..a365ae19 100644 --- a/share/functions/history.fish +++ b/share/functions/history.fish @@ -1,16 +1,12 @@ # -#Deletes an item from history +# Wrap the builtin history command to provide additional functionality. # -function history --description "Deletes an item from history" - +function history --shadow-builtin --description "Deletes an item from history" set -l argc (count $argv) set -l prefix_args "" set -l contains_args "" - set -l cmd print - set -l search_mode none - set -l pager less if set -q PAGER set pager $PAGER @@ -46,7 +42,7 @@ function history --description "Deletes an item from history" end end else - #Execute history builtin without any argument + # Execute history builtin without any argument. if status --is-interactive builtin history | eval $pager else @@ -57,9 +53,8 @@ function history --description "Deletes an item from history" switch $cmd case print - # Print matching items - # Note this may end up passing --search twice to the builtin, - # but that's harmless + # Print matching items. Note this may end up passing --search twice to the builtin, + # but that's harmless. builtin history --search $argv case delete @@ -72,8 +67,7 @@ function history --description "Deletes an item from history" set found_items (builtin history --search --contains $contains_args) case none builtin history $argv - - #Save changes after deleting item + # Save changes after deleting item. builtin history --save return 0 end @@ -98,7 +92,8 @@ function history --description "Deletes an item from history" continue end - #Following two validations could be embedded with "and" but I find the syntax kind of weird. + # Following two validations could be embedded with "and" but I find the syntax + # kind of weird. if not string match -qr '^[0-9]+$' $i printf "Invalid input: %s\n" $i continue @@ -124,18 +119,18 @@ function history --description "Deletes an item from history" end end - #Save changes after deleting item(s) + # Save changes after deleting item(s). builtin history --save end case save - #Save changes to history file + # Save changes to history file. builtin history $argv case merge builtin history --merge case help builtin history --help case clear - # Erase the entire history + # Erase the entire history. echo "Are you sure you want to clear history ? (y/n)" read ch if test $ch = "y" |