Skip to content

Instantly share code, notes, and snippets.

@ianchanning
Last active December 26, 2016 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianchanning/c9343a6df917ee36313a to your computer and use it in GitHub Desktop.
Save ianchanning/c9343a6df917ee36313a to your computer and use it in GitHub Desktop.
Basic windows history and bang commands (assuming Git installed)
@echo off
rem simple replacement for linux ! syntax e.g. !591
rem usage: ! N (executes line N of history.log)
rem @link http://ianchanning.wordpress.com/2014/10/29/dos-command-history/
if "%1"=="" goto Syntax
if "%1"=="/?" goto Syntax
for /f "tokens=*" %%x in ('sed -n "%1{p;q}" %USERPROFILE%\history.log') do echo %%x & cmd /c %%x
goto End
:Syntax
echo usage: ! N
:End
@echo off
rem replacement for linux `history` command
rem usage: history
rem @link http://ianchanning.wordpress.com/2014/10/29/dos-command-history/
set history_file=%USERPROFILE%\history.log
rem For if you are using Martin Ridgers 'clink'
rem @link http://mridgers.github.io/clink/
rem set history_file=%localappdata%\clink\.history
rem this doesn't require GNU Tools, but doesn't have line numbers
rem type history_file
rem requires GNU Tools installation (e.g. Git SCM)
cat -n %history_file%
@ianchanning
Copy link
Author

This is assuming that you've read my DOS command history post on outputting the DOS commands to %USERPROFILE%

@ianchanning
Copy link
Author

I recommend putting these files in the Git bin folder e.g. C:\Program Files\Git\bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment