File: gitroot

package info (click to toggle)
nnn 5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,184 kB
  • sloc: ansic: 11,902; sh: 3,585; makefile: 512; cpp: 80; python: 31; csh: 2
file content (15 lines) | stat: -rwxr-xr-x 365 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env sh

# Description: cd to the top level of the current git repository in the current context
# Dependencies: git
# Shell: sh
# Author: https://github.com/PatrickF1

root="$(git rev-parse --show-toplevel 2>/dev/null)"
if [ -n "$root" ]; then
    printf "%s" "0c$root" > "$NNN_PIPE"
else
    printf "Not in a git repository"
    read -r _
    exit 1
fi