実行したコマンドを簡単に記録し、メモも付加する。/How to easily record commands you ran and add notes
作業のログを取りたいとき、以前書いたような方法で全部のコマンドを記録することができます。しかし色々とコマンドを試しながら作業を進める場合、全部のコマンドを記録するのは無駄で、作業の各ステップで最終版のコマンドだけを選んで記録したいことがあります。また、それにメモ書きも加えたいところです。これを簡単に行うシェルの関数を紹介します。
When you want to record your operations, you can record every command by means like in my previous entries. But it's often meaningless to record all of your commands if you're trying to figure out how to do something. You may want to pick the final version of the commands for each step of your operation, and then want to add notes to explain what that command does. Here is an easy way to do that by some original functions of the shell.
以下を.bashrcか.zshrcに加えてください。
Add the following to your .bashrc or .zshrc
# Functions to record operations
function rcmd() {
touch commands.log
echo "# ---`date +%F_%T`---" >>commands.log
fc -ln | tail -n 1 >> commands.log
echo "Recorded: `tail -n 1 commands.log`"
}
function rnote() {
touch commands.log
echo "# $@" >> commands.log
echo -e "Recorded: `tail -n 1 commands.log`"
}
function rrun() {
chmod u+x commands.log
./commands.log
}
すると直前のコマンドの記録にはrcmd
、メモの付加にはrnote
が使えるようになります。さらにrrun
で記録したコマンドを実行できます。記録先はカレントディレクトリのcommands.log
です。記録先を選択するのは手間なので決め打ちにしています。以下実行例。
Now you can hit rcmd
to record your last command, rnote
to add notes with it, and rrun
to run saved commands. Commands are recorded to commands.log
in the current directory, which is hard-coded for simplicity.
> echo test
test
> rcmd
Recorded: echo test
> rnote just tested
Recorded: # just tested
> cat commands.log
# ---2017-10-11_21:00:00---
echo test
# just tested
> echo test2
test2
> rcmd
Recorded: echo test2
> rrun
test
test2
Author And Source
この問題について(実行したコマンドを簡単に記録し、メモも付加する。/How to easily record commands you ran and add notes), 我々は、より多くの情報をここで見つけました https://qiita.com/Ken-Kuroki/items/23c75862ad4d2797c635著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .