Added switch-branch.ps1

This commit is contained in:
Markus Fleschutz 2021-02-13 10:26:14 +01:00
parent 0d969091d0
commit 89c6ff871b
6 changed files with 57 additions and 15 deletions

View File

@ -89,6 +89,7 @@ speak-joke.ps1, speaks the next joke by text-to-speech (TTS)
speak-test.ps1, performs a speak test by text-to-speech (TTS)
speak-text.ps1, speaks the given text by text-to-speech (TTS)
speak-time.ps1, speaks the current time by text-to-speech (TTS)
switch-branch.ps1, switches to the given Git branch
switch-shelly1.ps1, switches a Shelly1 device in the local network
take-screenshot.ps1, takes a single screenshot
take-screenshots.ps1, takes multiple screenshots

1 Script Description
89 speak-test.ps1 performs a speak test by text-to-speech (TTS)
90 speak-text.ps1 speaks the given text by text-to-speech (TTS)
91 speak-time.ps1 speaks the current time by text-to-speech (TTS)
92 switch-branch.ps1 switches to the given Git branch
93 switch-shelly1.ps1 switches a Shelly1 device in the local network
94 take-screenshot.ps1 takes a single screenshot
95 take-screenshots.ps1 takes multiple screenshots

View File

@ -95,6 +95,7 @@ Table of Contents
* [speak-test.ps1](Scripts/speak-test.ps1) - performs a speak test by text-to-speech (TTS)
* [speak-text.ps1](Scripts/speak-text.ps1) - speaks the given text by text-to-speech (TTS)
* [speak-time.ps1](Scripts/speak-time.ps1) - speaks the current time by text-to-speech (TTS)
* [switch-branch.ps1](Scripts/switch-branch.ps1) - switches to the given Git branch
* [switch-shelly1.ps1](Scripts/switch-shelly1.ps1) - switches a Shelly1 device in the local network
* [take-screenshot.ps1](Scripts/take-screenshot.ps1) - takes a single screenshot
* [take-screenshots.ps1](Scripts/take-screenshots.ps1) - takes multiple screenshots

View File

@ -6,9 +6,15 @@
.NOTES Author: Markus Fleschutz / License: CC0
#>
$PathToRepo = "$PSScriptRoot/.."
try {
& git --version
} catch {
write-error "Can't execute 'git' - make sure Git is installed and available"
exit 1
}
try {
$PathToRepo = "$PSScriptRoot/.."
$Table = import-csv "$PathToRepo/Data/repos.csv"
foreach($Row in $Table) {
@ -16,11 +22,11 @@ try {
$Directory = $Row.Directory
write-output ""
if (Test-Path($Directory)) {
write-output "Skipping $Directory (already existent) ..."
write-output "Skipping existing $Directory ..."
continue
}
write-output "Cloning from $URL..."
git clone --recurse-submodules $URL
& git clone --recurse-submodules $URL
}
exit 0
} catch {

View File

@ -9,9 +9,9 @@
param($FullName = "", $EmailAddress = "", $FavoriteEditor = "")
try {
git --version
& git --version
} catch {
write-error "No Git installation found - make sure Git is installed"
write-error "Can't execute 'git' - make sure Git is installed and available"
exit 1
}
@ -25,15 +25,15 @@ try {
if ($FavoriteEditor -eq "") {
$FavoriteEditor = read-host "Enter your favorite text editor (emacs,nano,vi,vim,...)"
}
git config --global user.name $FullName
git config --global user.email $EmailAddress
git config --global core.editor $FavoriteEditor
git config --global http.sslVerify false
git config --global core.autocrlf false
git config --global core.symlinks true
git config --global init.defaultBranch main
& git config --global user.name $FullName
& git config --global user.email $EmailAddress
& git config --global core.editor $FavoriteEditor
& git config --global http.sslVerify false
& git config --global core.autocrlf false
& git config --global core.symlinks true
& git config --global init.defaultBranch main
write-host -foregroundColor green "Done - your Git user configuration is now:"
git config --list
& git config --list
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

27
Scripts/switch-branch.ps1 Executable file
View File

@ -0,0 +1,27 @@
#!/bin/powershell
<#
.SYNTAX ./switch-branch.ps1 [<branch>]
.DESCRIPTION switches to the given Git branch
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($Branch = "")
try {
& git --version
} catch {
write-error "Can't execute 'git' - make sure Git is installed and available"
exit 1
}
try {
if ($Branch -eq "") {
$Branch = read-host "Enter branch name to switch to"
}
& git switch --recurse-submodules $Branch
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -6,7 +6,14 @@
.NOTES Author: Markus Fleschutz / License: CC0
#>
param([string]$Directory = "")
param($Directory = "")
try {
& git --version
} catch {
write-error "Can't execute 'git' - make sure Git is installed and available"
exit 1
}
try {
if ($Directory -eq "") {
@ -19,7 +26,7 @@ try {
write-host ""
write-host -nonewline "Updating $Filename ..."
set-location $Filename
git pull
& git pull --recurse-submodules
set-location ..
}
}