Alternative of bash's `history -p` in zsh?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
In bash, history -p
does history expansion on its argument; What is the alternative in zsh?
zsh command-history history-expansion fc
add a comment |Â
up vote
2
down vote
favorite
In bash, history -p
does history expansion on its argument; What is the alternative in zsh?
zsh command-history history-expansion fc
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
In bash, history -p
does history expansion on its argument; What is the alternative in zsh?
zsh command-history history-expansion fc
In bash, history -p
does history expansion on its argument; What is the alternative in zsh?
zsh command-history history-expansion fc
zsh command-history history-expansion fc
asked Sep 3 at 11:38
HappyFace
1018
1018
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
I'm not aware of any, but see the histverify
option which changes the behaviour of history expansion so that when you press enter on a line that contains history operators, the expansion is performed in the editor buffer without running the command.
$ setopt histverify
$ echo !!Enter
$ echo setopt histverifyEnter
setopt histverify
Also note that in zsh
like in csh
(where history expansion comes from in the late 70s) history modifiers (like :h
, :r
, :A
...) can also be applied to parameter expansions ($var:h
...).
And the whole history is accessible with the $history
special associative array.
Keys of that associative arrays are the history numbers, and contrary to regular associative arrays where the order is undefined, $history[@]
is sorted in descending order on the numerical value of the key.
So $history:0:1
is the last history entry. So, you can use parameter expansion operators to get the same result as with history expansion operators. For instance: !$:h
, could be $$(z)history:0:1[-1]:h
add a comment |Â
up vote
0
down vote
In bash you can expand a command by doing this:
history -p !23
So if in 23 you have ls -l the, return will be:
ls
-l
In zsh i am able to reproduce a similar (but not identical) behavior by doing this:
history 23 23 | xargs -n1 | tail -n+2
1
ITYMhistory -p '!23'
. Inzsh
, just useprint -r -- $history[23]
â Stéphane Chazelas
Sep 3 at 15:02
I tried but nothing happens =(. Try history -p !23 instead of history -p '!23'... for what is really that ? =(
â Luciano Andress Martini
Sep 3 at 15:04
Thanks, but I need more sophisticated behavior; I wanted to runhistory -p '^(#b)E(?)^E$(l:2::0:)$((match[1]+1))'
. I wrote that function usingfc
in the end.
â HappyFace
Sep 4 at 17:49
I cant imagine the results you want to got. I just received "History Expansion Failed" (in bash). Can you post in you question what you have, and what exactly you want to get or do? Thank you. Maybe i have a easy solution!
â Luciano Andress Martini
Sep 4 at 17:54
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
I'm not aware of any, but see the histverify
option which changes the behaviour of history expansion so that when you press enter on a line that contains history operators, the expansion is performed in the editor buffer without running the command.
$ setopt histverify
$ echo !!Enter
$ echo setopt histverifyEnter
setopt histverify
Also note that in zsh
like in csh
(where history expansion comes from in the late 70s) history modifiers (like :h
, :r
, :A
...) can also be applied to parameter expansions ($var:h
...).
And the whole history is accessible with the $history
special associative array.
Keys of that associative arrays are the history numbers, and contrary to regular associative arrays where the order is undefined, $history[@]
is sorted in descending order on the numerical value of the key.
So $history:0:1
is the last history entry. So, you can use parameter expansion operators to get the same result as with history expansion operators. For instance: !$:h
, could be $$(z)history:0:1[-1]:h
add a comment |Â
up vote
2
down vote
I'm not aware of any, but see the histverify
option which changes the behaviour of history expansion so that when you press enter on a line that contains history operators, the expansion is performed in the editor buffer without running the command.
$ setopt histverify
$ echo !!Enter
$ echo setopt histverifyEnter
setopt histverify
Also note that in zsh
like in csh
(where history expansion comes from in the late 70s) history modifiers (like :h
, :r
, :A
...) can also be applied to parameter expansions ($var:h
...).
And the whole history is accessible with the $history
special associative array.
Keys of that associative arrays are the history numbers, and contrary to regular associative arrays where the order is undefined, $history[@]
is sorted in descending order on the numerical value of the key.
So $history:0:1
is the last history entry. So, you can use parameter expansion operators to get the same result as with history expansion operators. For instance: !$:h
, could be $$(z)history:0:1[-1]:h
add a comment |Â
up vote
2
down vote
up vote
2
down vote
I'm not aware of any, but see the histverify
option which changes the behaviour of history expansion so that when you press enter on a line that contains history operators, the expansion is performed in the editor buffer without running the command.
$ setopt histverify
$ echo !!Enter
$ echo setopt histverifyEnter
setopt histverify
Also note that in zsh
like in csh
(where history expansion comes from in the late 70s) history modifiers (like :h
, :r
, :A
...) can also be applied to parameter expansions ($var:h
...).
And the whole history is accessible with the $history
special associative array.
Keys of that associative arrays are the history numbers, and contrary to regular associative arrays where the order is undefined, $history[@]
is sorted in descending order on the numerical value of the key.
So $history:0:1
is the last history entry. So, you can use parameter expansion operators to get the same result as with history expansion operators. For instance: !$:h
, could be $$(z)history:0:1[-1]:h
I'm not aware of any, but see the histverify
option which changes the behaviour of history expansion so that when you press enter on a line that contains history operators, the expansion is performed in the editor buffer without running the command.
$ setopt histverify
$ echo !!Enter
$ echo setopt histverifyEnter
setopt histverify
Also note that in zsh
like in csh
(where history expansion comes from in the late 70s) history modifiers (like :h
, :r
, :A
...) can also be applied to parameter expansions ($var:h
...).
And the whole history is accessible with the $history
special associative array.
Keys of that associative arrays are the history numbers, and contrary to regular associative arrays where the order is undefined, $history[@]
is sorted in descending order on the numerical value of the key.
So $history:0:1
is the last history entry. So, you can use parameter expansion operators to get the same result as with history expansion operators. For instance: !$:h
, could be $$(z)history:0:1[-1]:h
edited Sep 3 at 16:19
answered Sep 3 at 14:21
Stéphane Chazelas
286k53527866
286k53527866
add a comment |Â
add a comment |Â
up vote
0
down vote
In bash you can expand a command by doing this:
history -p !23
So if in 23 you have ls -l the, return will be:
ls
-l
In zsh i am able to reproduce a similar (but not identical) behavior by doing this:
history 23 23 | xargs -n1 | tail -n+2
1
ITYMhistory -p '!23'
. Inzsh
, just useprint -r -- $history[23]
â Stéphane Chazelas
Sep 3 at 15:02
I tried but nothing happens =(. Try history -p !23 instead of history -p '!23'... for what is really that ? =(
â Luciano Andress Martini
Sep 3 at 15:04
Thanks, but I need more sophisticated behavior; I wanted to runhistory -p '^(#b)E(?)^E$(l:2::0:)$((match[1]+1))'
. I wrote that function usingfc
in the end.
â HappyFace
Sep 4 at 17:49
I cant imagine the results you want to got. I just received "History Expansion Failed" (in bash). Can you post in you question what you have, and what exactly you want to get or do? Thank you. Maybe i have a easy solution!
â Luciano Andress Martini
Sep 4 at 17:54
add a comment |Â
up vote
0
down vote
In bash you can expand a command by doing this:
history -p !23
So if in 23 you have ls -l the, return will be:
ls
-l
In zsh i am able to reproduce a similar (but not identical) behavior by doing this:
history 23 23 | xargs -n1 | tail -n+2
1
ITYMhistory -p '!23'
. Inzsh
, just useprint -r -- $history[23]
â Stéphane Chazelas
Sep 3 at 15:02
I tried but nothing happens =(. Try history -p !23 instead of history -p '!23'... for what is really that ? =(
â Luciano Andress Martini
Sep 3 at 15:04
Thanks, but I need more sophisticated behavior; I wanted to runhistory -p '^(#b)E(?)^E$(l:2::0:)$((match[1]+1))'
. I wrote that function usingfc
in the end.
â HappyFace
Sep 4 at 17:49
I cant imagine the results you want to got. I just received "History Expansion Failed" (in bash). Can you post in you question what you have, and what exactly you want to get or do? Thank you. Maybe i have a easy solution!
â Luciano Andress Martini
Sep 4 at 17:54
add a comment |Â
up vote
0
down vote
up vote
0
down vote
In bash you can expand a command by doing this:
history -p !23
So if in 23 you have ls -l the, return will be:
ls
-l
In zsh i am able to reproduce a similar (but not identical) behavior by doing this:
history 23 23 | xargs -n1 | tail -n+2
In bash you can expand a command by doing this:
history -p !23
So if in 23 you have ls -l the, return will be:
ls
-l
In zsh i am able to reproduce a similar (but not identical) behavior by doing this:
history 23 23 | xargs -n1 | tail -n+2
edited Sep 7 at 10:47
Rui F Ribeiro
36.8k1272117
36.8k1272117
answered Sep 3 at 14:57
Luciano Andress Martini
3,153829
3,153829
1
ITYMhistory -p '!23'
. Inzsh
, just useprint -r -- $history[23]
â Stéphane Chazelas
Sep 3 at 15:02
I tried but nothing happens =(. Try history -p !23 instead of history -p '!23'... for what is really that ? =(
â Luciano Andress Martini
Sep 3 at 15:04
Thanks, but I need more sophisticated behavior; I wanted to runhistory -p '^(#b)E(?)^E$(l:2::0:)$((match[1]+1))'
. I wrote that function usingfc
in the end.
â HappyFace
Sep 4 at 17:49
I cant imagine the results you want to got. I just received "History Expansion Failed" (in bash). Can you post in you question what you have, and what exactly you want to get or do? Thank you. Maybe i have a easy solution!
â Luciano Andress Martini
Sep 4 at 17:54
add a comment |Â
1
ITYMhistory -p '!23'
. Inzsh
, just useprint -r -- $history[23]
â Stéphane Chazelas
Sep 3 at 15:02
I tried but nothing happens =(. Try history -p !23 instead of history -p '!23'... for what is really that ? =(
â Luciano Andress Martini
Sep 3 at 15:04
Thanks, but I need more sophisticated behavior; I wanted to runhistory -p '^(#b)E(?)^E$(l:2::0:)$((match[1]+1))'
. I wrote that function usingfc
in the end.
â HappyFace
Sep 4 at 17:49
I cant imagine the results you want to got. I just received "History Expansion Failed" (in bash). Can you post in you question what you have, and what exactly you want to get or do? Thank you. Maybe i have a easy solution!
â Luciano Andress Martini
Sep 4 at 17:54
1
1
ITYM
history -p '!23'
. In zsh
, just use print -r -- $history[23]
â Stéphane Chazelas
Sep 3 at 15:02
ITYM
history -p '!23'
. In zsh
, just use print -r -- $history[23]
â Stéphane Chazelas
Sep 3 at 15:02
I tried but nothing happens =(. Try history -p !23 instead of history -p '!23'... for what is really that ? =(
â Luciano Andress Martini
Sep 3 at 15:04
I tried but nothing happens =(. Try history -p !23 instead of history -p '!23'... for what is really that ? =(
â Luciano Andress Martini
Sep 3 at 15:04
Thanks, but I need more sophisticated behavior; I wanted to run
history -p '^(#b)E(?)^E$(l:2::0:)$((match[1]+1))'
. I wrote that function using fc
in the end.â HappyFace
Sep 4 at 17:49
Thanks, but I need more sophisticated behavior; I wanted to run
history -p '^(#b)E(?)^E$(l:2::0:)$((match[1]+1))'
. I wrote that function using fc
in the end.â HappyFace
Sep 4 at 17:49
I cant imagine the results you want to got. I just received "History Expansion Failed" (in bash). Can you post in you question what you have, and what exactly you want to get or do? Thank you. Maybe i have a easy solution!
â Luciano Andress Martini
Sep 4 at 17:54
I cant imagine the results you want to got. I just received "History Expansion Failed" (in bash). Can you post in you question what you have, and what exactly you want to get or do? Thank you. Maybe i have a easy solution!
â Luciano Andress Martini
Sep 4 at 17:54
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466554%2falternative-of-bashs-history-p-in-zsh%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password