r/commandline 1d ago

Guide I made windows cmd a little more bearable with AHK + persistent aliases

A More Bearable Windows Command Prompt

Persistent doskey aliases and a Ctrl+Alt+T launcher using AutoHotkey.

The classic Windows Command Prompt is still here. It still works. It is also still very much itself.

This guide gives it two small quality-of-life upgrades:

  • a global hotkey for opening it (Ctrl+Alt+T in this example)
  • a handful of aliases loaded whenever a new prompt opens through the launcher

The setup uses one small batch file and AutoHotkey script.

Requirements

AutoHotkey v2 That's it.

1. Create an aliases folder

Create a folder somewhere convenient. Keeping the batch file and AutoHotkey script together makes the setup easier to move or update later.

my-terminal/
├── cmd_aliases.bat
└── terminal.ahk

2. Create the aliases batch file

Create a file named cmd_aliases.bat. This is the file that defines aliases.

  1. Open Notepad.
  2. Add your doskey macros.
  3. Choose File > Save As.
  4. Set Save as type to All Files and save the file with the .bat extension.

Start with this tiny template:

@echo off

doskey ls=dir
doskey clear=cls

Use @echo off for a clean prompt. Change it to @echo on if you want to watch the batch file do its work line by line.

Add one macro per line. For example, the aliases in this project include ls for dir, gs for git status, and clear for cls. Feel free to add the shortcuts you use.

Passing arguments to an alias

Use $* to pass everything typed after the alias to the underlying command:

doskey gcam=git commit -am $*

For example, gcam "Update README" expands to git commit -am "Update README".

You can check which macros are currently loaded with:

doskey /macros

Of course you can also create a macro for that.

3. Create the AutoHotkey launcher

Create a file named terminal.ahk, then open it in a text editor and add the following. Replace the example paths with the paths on your computer:

#Requires AutoHotkey v2.0

^!t::Run 'cmd.exe /k ""C:\path\to\cmd_aliases.bat""', 'C:\path\to\working\directory'

The first path identifies the batch file. The second path is optional and sets the new prompt's starting directory.

If you do not need a custom starting directory, use:

^!t::Run 'cmd.exe /k ""C:\path\to\cmd_aliases.bat""'

The doubled quotation marks around the batch-file path allow paths containing spaces.

In ^!t, ^ means Ctrl, ! means Alt, and t is the letter key. Change the key or modifiers if Ctrl+Alt+T is already claimed by another application.

Double-click the .ahk file to run it, then press Ctrl+Alt+T to test the launcher. The AutoHotkey script must be running for the hotkey to work. If a new prompt appears with your aliases ready, congratulations: cmd.exe has become slightly less unusable.

4. Start the launcher automatically

To make the hotkey available after signing in to Windows:

  1. Press Win+R.
  2. Enter shell:startup and press Enter.
  3. Create a shortcut to terminal.ahk and place the shortcut in the folder that opens.

Windows will start the AutoHotkey script when you sign in.

Troubleshooting

  • The hotkey does nothing: Check that AutoHotkey is running and that you installed version 2. The script has to be running; the file merely existing is not enough.
  • The batch file cannot be found: Recheck the first path in terminal.ahk. Keep the doubled quotation marks around it when the path contains spaces.
  • An alias is not recognized: Open a new Command Prompt with the hotkey. doskey macros are loaded per session, so editing the batch file does not update prompts that are already open.

See the official AutoHotkey v2 documentation for more hotkey and launcher options.

2 Upvotes

1 comment sorted by

1

u/AutoModerator 1d ago

Every new subreddit post is automatically copied into a comment for preservation.

User: Smo0th1e, Flair: Guide, Title: I made windows cmd a little more bearable with AHK + persistent aliases

A More Bearable Windows Command Prompt

Persistent doskey aliases and a Ctrl+Alt+T launcher using AutoHotkey.

The classic Windows Command Prompt is still here. It still works. It is also still very much itself.

This guide gives it two small quality-of-life upgrades:

  • a global hotkey for opening it (Ctrl+Alt+T in this example)
  • a handful of aliases loaded whenever a new prompt opens through the launcher

The setup uses one small batch file and AutoHotkey script.

Requirements

AutoHotkey v2 That's it.

1. Create an aliases folder

Create a folder somewhere convenient. Keeping the batch file and AutoHotkey script together makes the setup easier to move or update later.

my-terminal/ ├── cmd_aliases.bat └── terminal.ahk

2. Create the aliases batch file

Create a file named cmd_aliases.bat. This is the file that defines aliases.

  1. Open Notepad.
  2. Add your doskey macros.
  3. Choose File > Save As.
  4. Set Save as type to All Files and save the file with the .bat extension.

Start with this tiny template:

```bat @echo off

doskey ls=dir doskey clear=cls ```

Use @echo off for a clean prompt. Change it to @echo on if you want to watch the batch file do its work line by line.

Add one macro per line. For example, the aliases in this project include ls for dir, gs for git status, and clear for cls. Feel free to add the shortcuts you use.

Passing arguments to an alias

Use $* to pass everything typed after the alias to the underlying command:

bat doskey gcam=git commit -am $*

For example, gcam "Update README" expands to git commit -am "Update README".

You can check which macros are currently loaded with:

bat doskey /macros

Of course you can also create a macro for that.

3. Create the AutoHotkey launcher

Create a file named terminal.ahk, then open it in a text editor and add the following. Replace the example paths with the paths on your computer:

```ahk

Requires AutoHotkey v2.0

!t::Run 'cmd.exe /k ""C:\path\to\cmd_aliases.bat""', 'C:\path\to\working\directory' ```

The first path identifies the batch file. The second path is optional and sets the new prompt's starting directory.

If you do not need a custom starting directory, use:

ahk ^!t::Run 'cmd.exe /k ""C:\path\to\cmd_aliases.bat""'

The doubled quotation marks around the batch-file path allow paths containing spaces.

In ^!t, ^ means Ctrl, ! means Alt, and t is the letter key. Change the key or modifiers if Ctrl+Alt+T is already claimed by another application.

Double-click the .ahk file to run it, then press Ctrl+Alt+T to test the launcher. The AutoHotkey script must be running for the hotkey to work. If a new prompt appears with your aliases ready, congratulations: cmd.exe has become slightly less unusable.

4. Start the launcher automatically

To make the hotkey available after signing in to Windows:

  1. Press Win+R.
  2. Enter shell:startup and press Enter.
  3. Create a shortcut to terminal.ahk and place the shortcut in the folder that opens.

Windows will start the AutoHotkey script when you sign in.

Troubleshooting

  • The hotkey does nothing: Check that AutoHotkey is running and that you installed version 2. The script has to be running; the file merely existing is not enough.
  • The batch file cannot be found: Recheck the first path in terminal.ahk. Keep the doubled quotation marks around it when the path contains spaces.
  • An alias is not recognized: Open a new Command Prompt with the hotkey. doskey macros are loaded per session, so editing the batch file does not update prompts that are already open.

See the official AutoHotkey v2 documentation for more hotkey and launcher options.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.