Skip to content

Commit

Permalink
cmd/gen: Create alias function for Windows PowerShell
Browse files Browse the repository at this point in the history
Closes #20
  • Loading branch information
jmooring authored Sep 20, 2023
1 parent 016230c commit 0a376a3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ valid `.hvm` file exists in the current directory.

1. Run `hvm gen alias --help` to find the subcommand for the desired shell.
2. Run `hvm gen alias <shell> --help` to see the installation instructions.
3. Run `hvm gen alias <shell>` to generate the alias script.
3. Run `hvm gen alias <shell>` to generate an alias function for the specified shell.

The `hvm gen alias` command generates alias scripts for bash, fish, zsh, and Windows PowerShell.
The `hvm gen alias` command generates alias functions for bash, fish, zsh, and Windows PowerShell.

The alias script displays a brief status message each time it is called, if version management is enabled in the current directory. To disable this message, set the `hvm_show_status` variable to `false` in the alias script.
The alias function displays a brief status message each time it is called, if version management is enabled in the current directory. To disable this message, set the `hvm_show_status` variable to `false` in the alias function.

## Usage

Expand Down
6 changes: 3 additions & 3 deletions cmd/hvm/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
// aliasCmd represents the alias command
var aliasCmd = &cobra.Command{
Use: "alias",
Short: "Generate the alias script for the specified shell",
Long: `Generate the alias script for the specified shell.
See each sub-command's help for details on how to use the generated script.`,
Short: "Generate an alias function for the specified shell",
Long: `Generate an alias function for the specified shell.
See each sub-command's help for details on how to use the generated code.`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
Expand Down
21 changes: 19 additions & 2 deletions cmd/hvm/alias_scripts/powershell.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Hugo Version Manager: override path to the hugo executable.

TBD
function Hugo-Override {
Set-Variable -Name "hvm_show_status" -Value $true
Set-Variable -Name "hugo_bin" -Value $(hvm status --printExecPath)
If ($hugo_bin) {
If ($hvm_show_status) {
echo "Hugo version management is enabled in this directory."
echo "Run 'hvm status' for details, or 'hvm disable' to disable.`n"
}
& "$hugo_bin" $args
} Else {
Set-Variable -Name "hugo_bin" -Value $((gcm hugo.exe).Path 2> $null)
If ($hugo_bin) {
& "$hugo_bin" $args
} Else {
echo "Command not found"
}
}
}
Set-Alias hugo Hugo-Override
8 changes: 4 additions & 4 deletions cmd/hvm/bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ var bashScript string
// bashCmd represents the bash command
var bashCmd = &cobra.Command{
Use: "bash",
Short: "Generate the alias script for bash",
Long: `Generate the alias script for the bash shell.
Short: "Generate an alias function for bash",
Long: `Generate an alias function for the bash shell.
Add the output from this command to $HOME/.bashrc or $HOME/.bash_aliases.
Open a new shell to activate the alias.
The alias script displays a brief status message each time it is called, if
The alias function displays a brief status message each time it is called, if
version management is enabled in the current directory. To disable this
message, set the "hvm_show_status" variable to "false" in the alias script.`,
message, set the "hvm_show_status" variable to "false" in the alias function.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(bashScript)
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/hvm/fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ var fishScript string
// fishCmd represents the fish command
var fishCmd = &cobra.Command{
Use: "fish",
Short: "Generate the alias script for fish",
Long: `Generate the alias script for the fish shell.
Short: "Generate an alias function for fish",
Long: `Generate an alias function for the fish shell.
Add the output from this command to $HOME/.config/fish/config.fish.
Open a new shell to activate the alias.
The alias script displays a brief status message each time it is called, if
The alias function displays a brief status message each time it is called, if
version management is enabled in the current directory. To disable this
message, set the "hvm_show_status" variable to "false" in the alias script.`,
message, set the "hvm_show_status" variable to "false" in the alias function.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(fishScript)
},
Expand Down
17 changes: 13 additions & 4 deletions cmd/hvm/powershell.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ var powershellScript string
// powershellCmd represents the powershell command
var powershellCmd = &cobra.Command{
Use: "powershell",
Short: "Generate the alias script for zsh",
Long: `Generate the alias script for powershell.
Short: "Generate an alias function for powershell",
Long: `Generate an alias function for Windows PowerShell.
The alias script displays a brief status message each time it is called, if
Instructions:
1. Create a PowerShell profile: New-Item -Path $profile -ItemType File
2. Open the file with Notepad: notepad $profile
3. Add the output from this command to the file you just opened
4. Save the file and exit Notepad
5. Refresh the current session: . $profile
The alias function displays a brief status message each time it is called, if
version management is enabled in the current directory. To disable this
message, set the "hvm_show_status" variable to "false" in the alias script.`,
message, set the "hvm_show_status" variable to "$false" in the alias function.
`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(powershellScript)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/hvm/testscripts/gen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exec hvm gen
stdout 'Generate various files.\n'

exec hvm gen alias
stdout 'Generate the alias script for the specified shell.\n'
stdout 'Generate an alias function for the specified shell.\n'

exec hvm gen alias bash
stdout '# Hugo Version Manager: override path to the hugo executable.'
Expand Down
8 changes: 4 additions & 4 deletions cmd/hvm/zsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ var zshScript string
// zshCmd represents the zsh command
var zshCmd = &cobra.Command{
Use: "zsh",
Short: "Generate the alias script for zsh",
Long: `Generate the alias script for the zsh shell.
Short: "Generate an alias function for zsh",
Long: `Generate an alias function for the zsh shell.
Add the output from this command to $HOME/.zshrc.
Open a new shell to activate the alias.
The alias script displays a brief status message each time it is called, if
The alias function displays a brief status message each time it is called, if
version management is enabled in the current directory. To disable this
message, set the "hvm_show_status" variable to "false" in the alias script.`,
message, set the "hvm_show_status" variable to "false" in the alias function.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(zshScript)
},
Expand Down

0 comments on commit 0a376a3

Please sign in to comment.