I want to leave an arbitrary command in the command history of Shell

Problem In many cases, it is more convenient to leave the result in history than the command when using Interactive filter.

#Example: Open the file selected with fzf with vim
alias v='_vim_fzf'
_vim_fzf () {
  local file
  file=$(fzf +m -q "$1") && vim "$file"
}

In the above case, the selected file does not appear even if you go back in history.

Solution Bash uses history -s.

_vim_fzf () {
  local file
  file=$(fzf +m -q "$1") && history -s "vim $file" && vim "$file"
}

If you rewrite it like this, the vim [selected file] will be recorded in the history instead of the v command, so you can reopen the file with Ctrl-R or Ctrl-P.

Further Work (Zsh) In Zsh, print -s seems to be equivalent.

$ print -s "alternative command"
$ history
# ...
#  99 print -s "alternative command"
# 100 alternative command

The problem is that the print command itself is also saved as above. Please let me know if there is a better way mm

Recommended Posts

I want to leave an arbitrary command in the command history of Shell
I want to know the population of each country in the world.
[For beginners] I want to explain the number of learning times in an easy-to-understand manner.
I want to extract an arbitrary URL from the character string of the html source with python
I want to explain the abstract class (ABCmeta) of Python in detail.
I want to sort a list in the order of other lists
I want to color a part of an Excel string in Python
I want to customize the appearance of zabbix
I want to display the progress in Python!
How to pass the execution result of a shell command in a list in Python
[Python] I want to know the variables in the function when an error occurs!
I want to use Python in the environment of pyenv + pipenv on Windows 10
I want to set a life cycle in the task definition of ECS
I want to see a list of WebDAV files in the Requests module
I want to grep the execution result of strace
I want to write in Python! (3) Utilize the mock
I want to automate ssh using the expect command!
I want to use the R dataset in python
I want to increase the security of ssh connections
I want to use Linux commands at the command prompt! Use Linux commands at the command prompt instead of Git Bash
I want to automate ssh using the expect command! part2
I want to use only the normalization process of SudachiPy
I want to judge the authenticity of the elements of numpy array
I want to know the features of Python and pip
I want to make the Dictionary type in the List unique
Keras I want to get the output of any layer !!
I want to align the significant figures in the Numpy array
I want to know the legend of the IT technology world
I didn't want to write the AWS key in the program
linux / c> link> Get the execution result of the shell command in the C program> I was taught how to use popen ()
In the python command python points to python3.8
How to pass the execution result of a shell command in a list in Python (non-blocking version)
I made a program in Python that changes the 1-minute data of FX to an arbitrary time frame (1 hour frame, etc.)
How to intentionally issue an error in the shell During testing
I want to get the name of the function / method being executed
[Linux] I tried to summarize the command of resource confirmation system
I want to manually assign the training parameters of the [Pytorch] model
How to know the internal structure of an object in Python
[Linux] I want to know the date when the user logged in
I want to read the html version of "OpenCV-Python Tutorials" OpenCV 3.1 version
LINEbot development, I want to check the operation in the local environment
I tried to make an analysis base of 5 patterns in 3 years
I want to make the second line the column name in pandas
I want to connect remotely to another computer, and the nautilus command
I want to pass the G test in one month Day 1
I want to check the position of my face with OpenCV!
I used the worldcup command to check the outcome of the World Cup.
I made a command to display a colorful calendar in the terminal
I want to pin Spyder to the taskbar
I want to output to the console coolly
I tried to summarize the umask command
The story of an error in PyOCR
I want to print in a comprehension
I want to handle the rhyme part1
I want to handle the rhyme part3
I want to display the progress bar
I want to embed Matplotlib in PySimpleGUI
I want to handle the rhyme part2
I want to handle the rhyme part5
I want to handle the rhyme part4
I want to change the color by clicking the scatter point in matplotlib