Featured image of post Use an alias in your PowerShell profile to create a new Hugo post

Use an alias in your PowerShell profile to create a new Hugo post

The command to create a new Hugo post is:

1
hugo new <path to new content>

Use an alias

Using Powershell, you can use an alias to make this easier, here is the block of code we are going to use:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function New-HugoPost {
  param (
    [string]$PostName
  )
 
  # UPDATE ME TO POINT TO YOUR BLOG PATH
  $blogPath = "c:\path\to\your\blog"

  set-location $blogPath
  & hugo.exe new "content\post\$PostName\index.md" -c $blogPath
}

Set-Alias nhp New-HugoPost

This can be reloaded each time Powershell starts by editing your profile:

1
2
3
4
5
6
7
# open up the profile
notepad $profile
#
# ** paste in the code block above & save **
# 
# reload the profile
. $profile

Test it works

Then, to create a new post using the new, friendly nhp alias:

1
nhp my-new-post
Licensed under CC BY-NC-SA 4.0, unless noted by credits.
Built with Hugo
Theme Stack designed by Jimmy