Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ tmp/
.bundle/
_site/
Gemfile.lock
.goxc.local.json
*.exe
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# build the binary
# note starting in go1.18 vcs information will be available via go version -m
# set version in main.go for `go install` and build binary
build:
$(eval VERSION := $(shell git describe --tags HEAD 2>/dev/null || echo unknown))
@echo "Building as version: $(VERSION)"
$(shell sed -E -i '' -e "s/^var version = \"[A-Za-z0-9\.-_]+\"/var version = \"$(VERSION)\"/" main.go)
go build -o bin/scmpuff -mod=readonly -ldflags "-X main.version=$(VERSION)"

# run unit tests
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ This will define the scmpuff shell functions as well as some handy shortcuts.

[fish]: https://fishshell.com/

For Powershell on Windows, add the following to your `$PROFILE` file:

scmpuff init --shell=pwsh | Out-String | Invoke-Expression


## Usage

Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module github.com/mroth/scmpuff
module github.com/kmatt/scmpuff

go 1.24

require (
github.com/google/go-cmp v0.7.0
github.com/spf13/cobra v1.9.1
)
require github.com/spf13/cobra v1.9.1

require github.com/google/go-cmp v0.7.0

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"os/exec"

"github.com/mroth/scmpuff/internal/arguments"
"github.com/kmatt/scmpuff/internal/arguments"
"github.com/spf13/cobra"
)

Expand All @@ -16,7 +16,7 @@ var expandRelative bool
// Allows expansion of numbered shortcuts, ranges of shortcuts, or standard paths.
// Numbered shortcut variables are produced by various commands, such as:
//
// * scmpuff_status() - git status implementation
// - scmpuff_status() - git status implementation
func CommandExec() *cobra.Command {

var expandCmd = &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/expand/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"regexp"
"strings"

"github.com/mroth/scmpuff/internal/arguments"
"github.com/kmatt/scmpuff/internal/arguments"
"github.com/spf13/cobra"
)

Expand Down
6 changes: 6 additions & 0 deletions internal/commands/inits/data/aliases.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function gs { scmpuff_status }
function ga { git add }
function gd { git diff }
function gl { git log }
function gco { git checkout }
function grs { git reset }
19 changes: 19 additions & 0 deletions internal/commands/inits/data/git_wrapper.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$SCMPUFF_GIT_CMD = Get-Command git | Select-Object -ExpandProperty Definition

function git {
switch -regex -casesensitive($args[0]) {
"^(commit|blame|log|rebase|merge)$" {
& scmpuff exec -- $SCMPUFF_GIT_CMD $args
}
"^(checkout|diff|rm|reset)$" {
& scmpuff exec --relative -- $SCMPUFF_GIT_CMD $args
}
"^add$" {
& scmpuff exec -- $SCMPUFF_GIT_CMD $args
scmpuff_status
}
default {
& $SCMPUFF_GIT_CMD $args
}
}
}
42 changes: 42 additions & 0 deletions internal/commands/inits/data/status_shortcuts.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function scmpuff_status {
$scmpuff_env_char = "e"

# Run scmpuff status command and capture the output
$cmd_output = & scmpuff status --filelist @args

# if there was an error, exit prematurely, and pass along the exit code
$es = $LastExitCode
if ($es -ne 0) {
return $es
}

# Fetch list of files (from first line of script output)
$files = ($cmd_output | Select-Object -First 1) -split '\s+'

# Export numbered env variables for each file
scmpuff_clear_vars
$e = 1
foreach ($file in $files) {
Set-Item "env:$($scmpuff_env_char + $e)" $file
$e++
}

# Print status (from line two onward)
$cmd_output | Select-Object -Skip 1
}

# Clear numbered env variables
function scmpuff_clear_vars {
# Define the environment variable character
$scmpuff_env_char = "e"

# Iterate through environment variables and unset those starting with 'e'
for ($i = 1; $i -le 999; $i++) {
$env_var_i = $scmpuff_env_char + $i
if (Get-Item "env:$($env_var_i)" -ErrorAction Ignore) {
Remove-Item "env:$env_var_i"
} else {
break
}
}
}
8 changes: 6 additions & 2 deletions internal/commands/inits/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ There are a number of flags to customize the shell integration.
fmt.Println(fishCollection.Output(wrapGit, includeAliases))
os.Exit(0)

case "pwsh":
fmt.Println(pwshCollection.Output(wrapGit, includeAliases))
os.Exit(0)

default:
fmt.Fprintf(os.Stderr, "Unrecognized shell '%s'\n", shellType)
os.Exit(1)
Expand Down Expand Up @@ -88,7 +92,7 @@ There are a number of flags to customize the shell integration.
InitCmd.Flags().StringVarP(
&shellType,
"shell", "s", "",
"Output shell type: sh | bash | zsh | fish",
"Output shell type: sh | bash | zsh | fish | pwsh",
)
InitCmd.Flag("shell").NoOptDefVal = defaultShellType()

Expand All @@ -101,7 +105,7 @@ func defaultShellType() string {
if shellenv, ok := os.LookupEnv("SHELL"); ok {
base := filepath.Base(shellenv)
switch base {
case "sh", "bash", "zsh", "fish":
case "sh", "bash", "zsh", "fish", "pwsh":
return base
}
}
Expand Down
15 changes: 15 additions & 0 deletions internal/commands/inits/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ var scriptStatusShortcuts string
//go:embed data/status_shortcuts.fish
var scriptStatusShortcutsFish string

//go:embed data/status_shortcuts.ps1
var scriptStatusShortcutsPwsh string

//go:embed data/aliases.sh
var scriptAliases string

//go:embed data/aliases.ps1
var scriptAliasesPwsh string

//go:embed data/git_wrapper.sh
var scriptGitWrapper string

//go:embed data/git_wrapper.fish
var scriptGitWrapperFish string

//go:embed data/git_wrapper.ps1
var scriptGitWrapperPwsh string

type scriptCollection struct {
statusShortcuts string
gitWrapper string
Expand All @@ -38,6 +47,12 @@ var fishCollection = scriptCollection{
aliases: scriptAliases,
}

var pwshCollection = scriptCollection{
statusShortcuts: scriptStatusShortcutsPwsh,
gitWrapper: scriptGitWrapperPwsh,
aliases: scriptAliasesPwsh,
}

func (sc scriptCollection) Output(wrapGit, aliases bool) string {
var b strings.Builder
b.WriteString(sc.statusShortcuts)
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/status/color.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package status

import "github.com/mroth/scmpuff/internal/gitstatus"
import "github.com/kmatt/scmpuff/internal/gitstatus"

// Color represents an ANSI color code
type Color string
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/status/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
"strings"

"github.com/mroth/scmpuff/internal/gitstatus"
"github.com/kmatt/scmpuff/internal/gitstatus"
)

// A Renderer formats git status information for display to the screen.
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/status/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"testing"

"github.com/mroth/scmpuff/internal/gitstatus"
"github.com/kmatt/scmpuff/internal/gitstatus"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os/exec"
"path/filepath"

"github.com/mroth/scmpuff/internal/gitstatus/porcelainv1"
"github.com/kmatt/scmpuff/internal/gitstatus/porcelainv1"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/gitstatus/porcelainv1/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/mroth/scmpuff/internal/gitstatus"
"github.com/kmatt/scmpuff/internal/gitstatus"
)

func TestProcess(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/gitstatus/porcelainv1/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"regexp"
"strconv"

"github.com/mroth/scmpuff/internal/gitstatus"
"github.com/kmatt/scmpuff/internal/gitstatus"
)

// Process takes the raw output of `git status --porcelain=v1 -b -z` and
Expand Down
2 changes: 1 addition & 1 deletion internal/gitstatus/porcelainv1/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"slices"
"testing"

"github.com/mroth/scmpuff/internal/gitstatus"
"github.com/kmatt/scmpuff/internal/gitstatus"
)

func Test_extractFilePaths(t *testing.T) {
Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package main
import (
"fmt"

"github.com/mroth/scmpuff/internal/commands/exec"
"github.com/mroth/scmpuff/internal/commands/expand"
"github.com/mroth/scmpuff/internal/commands/inits"
"github.com/mroth/scmpuff/internal/commands/intro"
"github.com/mroth/scmpuff/internal/commands/status"
"github.com/kmatt/scmpuff/internal/commands/exec"
"github.com/kmatt/scmpuff/internal/commands/expand"
"github.com/kmatt/scmpuff/internal/commands/inits"
"github.com/kmatt/scmpuff/internal/commands/intro"
"github.com/kmatt/scmpuff/internal/commands/status"

"github.com/spf13/cobra"

_ "embed"
)

// version is the default version of the program
// ...in almost all cases this should be overriden by the buildscript.
var version = "0.0.0-development"
var version = "v0.5.0"

var puffCmd = &cobra.Command{
Use: "scmpuff",
Expand Down