Skip to content

docs: add a cmd.exe version of the cd snippet #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2023
Merged

docs: add a cmd.exe version of the cd snippet #1048

merged 2 commits into from
May 8, 2023

Conversation

mataha
Copy link
Contributor

@mataha mataha commented May 7, 2023

Hello,

I would like to include a snippet that presents usage of git combined with onefetch in cmd.exe, as I felt Windows shells were heavily underrepresented on that front.

It is suited for use in AutoRun scripts (something akin to .bashrc or .bash_profile, but isn't enabled by default).

Copy link
Collaborator

@spenserblack spenserblack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is far beyond my knowledge of Windows cmd.exe, but LGTM 😆

Copy link
Owner

@o2sh o2sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mataha, awesome script! Too bad that I can't add it to my $PROFILE as a PowerShell script, but thank you so much for sharing it 🙏. Your contribution is greatly appreciated! 👍

I'll let you address @spenserblack remark before merging it.

@mataha
Copy link
Contributor Author

mataha commented May 8, 2023

Re: your comment - this can be formatted, but every linebreak has to be escaped and the escape has to be in a context in which whitespace characters are not significant, otherwise indentation will cause an error:

@set LAST_REPOSITORY=

@doskey cd = @( ^
    if "$*"=="" ( ^
        chdir /d "%%USERPROFILE%%" ^
    ) else ( ^
        chdir /d $* ^
    ) ^
) ^&^& ( ^
    for /f "usebackq tokens=* delims=" %%i in ( ^
        `"@git rev-parse --show-toplevel 2$Gnul"` ^
    ) do @( ^
        if not "%%~i"=="" if not "%%~i"=="%%LAST_REPOSITORY%%" ( ^
            onefetch ^& set "LAST_REPOSITORY=%%~i" ^
        ) ^
    ) ^
)

Does it look better? Honestly, I don't know...

@o2sh
Copy link
Owner

o2sh commented May 9, 2023

otherwise indentation will cause an error

Yeah that's a shame. I think we can keep it as is 👍

Thanks for the effort though @mataha

@mataha mataha deleted the wiki/cmd-cd-onefetch branch May 17, 2023 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants