Skip to content

Instantly share code, notes, and snippets.

@Alby11
Last active November 2, 2023 02:49
Show Gist options
  • Select an option

  • Save Alby11/4b1c4c7a9a8e774331799a2a2d8504b9 to your computer and use it in GitHub Desktop.

Select an option

Save Alby11/4b1c4c7a9a8e774331799a2a2d8504b9 to your computer and use it in GitHub Desktop.
powershell core convenience functions for setting up or restoring dotfiles bare repo
# .setup_dotfiles.ps1
@"
convenience functions for setting up or restoring dotfiles bare repo
to call them, create a Gist and use something like:
---
$gistURL="https://gist.githubusercontent.com/Alby11/4b1c4c7a9a8e774331799a2a2d8504b9/raw/5180697b2285dfa5ba1aa35166af65bf6fa39b06/.setup_dotfiles.ps1"
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
# iwr -useb $gistURL | iex
Invoke-Expression $(curl $gistURL|Out-String)
dotfilesRestore [dotfiles repo]
---
Credits to: Jonathan Bowman
https://dev.to/bowmanjd/store-home-directory-config-files-dotfiles-in-git-using-bash-zsh-or-powershell-the-bare-repo-approach-35l3
"@
$dotDir="$HOME/.dotfiles_git/"
$dotBranch="main"
function dotfiles {
git --git-dir="$dotDir" --work-tree="$HOME" @Args
}
function dotfilesNew {
Param ([string]$repo)
git clone --bare $repo $dotDir
dotfiles config --local status.showUntrackedFiles no
dotfiles switch -c $dotBranch
echo "Please add and commit additional files"
echo "using 'dotfiles add' and 'dotfiles commit', then run"
echo "dotfiles push -u origin dotBranch"
}
function dotfilesRestore {
Param ([string]$repo)
git clone -b $dotBranch --bare $repo $dotDir
dotfiles config --local status.showUntrackedFiles no
dotfiles checkout
if ($LASTEXITCODE) {
echo "Deal with conflicting files, then run (possibly with -f flag if you are OK with overwriting)"
echo "dotfiles checkout"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment