Search code examples
windowscommand-promptdotfiles

How to create custom function Windows command prompt and set up "dotfile"-like system


How can I create a "dotfile" on Windows with custom functions to run in command prompt (not PowerShell)? A related question is, where should I save the file? There are a ton of resources for this for bash/unix, but I haven't found anything clear on (1) syntax for windows cmd prompt custom functions; or (2) where/how to save functions so that they automatically load (and can be backed up like dotfiles for easy configuration on new machines).

An example function I'd like to have is adding a prefix string to all files in a folder. I am tired of typing for %a in (*) do ren "%a" "prefix_%a" many times a day. Thank you for any help.


Solution

  • Use the AutoRun registry entry to run a batch file. Just be careful that you only do this when cmd.exe is started manually.

    This batch file may use doskey to store alias command for things you type often. You can also set options for other programs etc.:

    @echo off
    set GREP_OPTIONS=--binary-files=text -d skip --color=auto
    set LS_OPTIONS=-bhAC --color=auto --recent --streams
    doskey vcd=pushd %%$*%%
    rem More doskey macros here...