Skip to content

Commit 37daccd

Browse files
authored
Powershell snippet (#1453)
1 parent 465ccc7 commit 37daccd

File tree

1 file changed

+67
-11
lines changed

1 file changed

+67
-11
lines changed

.github/wiki/Getting-Started.md

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ Onefetch is installed, then what?
55
```sh
66
> onefetch /path/of/your/repo
77
```
8+
89
Or
9-
10+
1011
```sh
1112
> cd /path/of/your/repo
1213
> onefetch
@@ -15,38 +16,50 @@ Onefetch is installed, then what?
1516
### Misc
1617

1718
By [**@spenserblack**](https://github.com/spenserblack)
19+
1820
```sh
1921
# Runs `onefetch -a Assembly`, `onefetch -a C`, etc.
2022
onefetch -l | tr "[:upper:] " "[:lower:]-" | while read line; do echo "$line"; onefetch -a $line; done;
2123
```
24+
25+
### Automatic repo detection and running
26+
27+
If you want to automate the detection and running of `onefetch` every time you `cd` into a repository you can leverage one of the methods below:
28+
29+
#### 1. Bash / Zsh
30+
2231
By [**@quazar-omega**](https://github.com/quazar-omega)
2332

2433
A script to put in your `.bashrc` - or `.zshrc` - to run onefetch whenever you open a shell into a repository or `cd` into a repository, making sure that it's different from the last one you were in:
34+
2535
```sh
2636
# git repository greeter
2737
last_repository=
2838
check_directory_for_new_repository() {
29-
current_repository=$(git rev-parse --show-toplevel 2> /dev/null)
30-
31-
if [ "$current_repository" ] && \
32-
[ "$current_repository" != "$last_repository" ]; then
33-
onefetch
34-
fi
35-
last_repository=$current_repository
39+
current_repository=$(git rev-parse --show-toplevel 2> /dev/null)
40+
41+
if [ "$current_repository" ] && \
42+
[ "$current_repository" != "$last_repository" ]; then
43+
onefetch
44+
fi
45+
last_repository=$current_repository
3646
}
3747
cd() {
38-
builtin cd "$@"
39-
check_directory_for_new_repository
48+
builtin cd "$@"
49+
check_directory_for_new_repository
4050
}
4151

4252
# optional, greet also when opening shell directly in repository directory
4353
# adds time to startup
4454
check_directory_for_new_repository
4555
```
4656

57+
#### 2. Fish
58+
4759
By [**@TheSast**](https://github.com/TheSast)
4860

4961
A fish adaptation of the previous script, run it once in your shell to save it:
62+
5063
```fish
5164
function cd -w='cd'
5265
builtin cd $argv || return
@@ -66,11 +79,14 @@ funcsave cd
6679
funcsave check_directory_for_new_repository
6780
```
6881

82+
#### 3. CMD
83+
6984
By [**@mataha**](https://github.com/mataha)
7085

7186
An adaptation of the above snippet suited for Windows's `cmd.exe`,
7287
specifically for inclusion in AutoRun scripts or DOSKEY macrofiles:
73-
```batchfile
88+
89+
```bat
7490
@set LAST_REPOSITORY=
7591
7692
@doskey cd = ( ^
@@ -102,7 +118,47 @@ specifically for inclusion in AutoRun scripts or DOSKEY macrofiles:
102118
)
103119
```
104120

121+
#### 4. Powershell
122+
123+
By [**@kiapanahi**](https://github.com/kiapanahi)
124+
125+
An adaptation of the above snippet suited for `Powershell`. Put this script in the `$PROFILE`.
126+
127+
```pwsh
128+
# git repository greeter
129+
$global:lastRepository = $null
130+
131+
function Check-DirectoryForNewRepository {
132+
$currentRepository = git rev-parse --show-toplevel 2>$null
133+
if ($currentRepository -and ($currentRepository -ne $global:lastRepository)) {
134+
onefetch
135+
}
136+
$global:lastRepository = $currentRepository
137+
}
138+
139+
function Set-Location {
140+
param (
141+
[string]$path
142+
)
143+
144+
# Use the default Set-Location to change the directory
145+
Microsoft.PowerShell.Management\Set-Location -Path $path
146+
147+
# Check if we are in a new Git repository
148+
Check-DirectoryForNewRepository
149+
}
150+
151+
# Optional: Check the repository also when opening a shell directly in a repository directory
152+
# Uncomment the following line if desired
153+
#Check-DirectoryForNewRepository
154+
```
155+
156+
### Git alias
157+
105158
By [**@mbrehin**](https://github.com/mbrehin)
159+
160+
You can also add git alias to run onefetch during your git workflows
161+
106162
```sh
107163
# Add Git alias for onefetch.
108164
git config --global alias.project-summary '!which onefetch && onefetch'

0 commit comments

Comments
 (0)