Skip to content

Commit

Permalink
feat: hyperlink
Browse files Browse the repository at this point in the history
  • Loading branch information
lnu committed Jan 2, 2021
1 parent a9ece8b commit e48ec5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
9 changes: 6 additions & 3 deletions src/segment_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type gitRepo struct {
ahead int
behind int
HEAD string
PRETTYHEAD string
upstream string
stashCount string
root string
Expand Down Expand Up @@ -141,9 +142,10 @@ func (g *git) string() string {
fmt.Fprintf(buffer, "%s", g.getUpstreamSymbol())
}
if enableHyperlink {
fmt.Fprintf(buffer, "]8;;%s\\%s]8;;\\", g.repo.url, g.repo.HEAD)
url := strings.Replace(g.repo.url, ".git", "", -1)
fmt.Fprintf(buffer, "]8;;%s\\%s]8;;\\", fmt.Sprintf("%s/tree/%s", url, g.repo.HEAD), g.repo.PRETTYHEAD)
} else {
fmt.Fprintf(buffer, "%s", g.repo.HEAD)
fmt.Fprintf(buffer, "%s", g.repo.PRETTYHEAD)
}
displayStatus := g.props.getBool(DisplayStatus, true)
if !displayStatus {
Expand Down Expand Up @@ -222,7 +224,8 @@ func (g *git) setGitStatus() {
g.repo.upstream = status["upstream"]
}
}
g.repo.HEAD = g.getGitHEADContext(status["local"])
g.repo.HEAD = status["local"]
g.repo.PRETTYHEAD = g.getGitHEADContext(status["local"])
g.repo.stashCount = g.getStashContext()
}

Expand Down
25 changes: 15 additions & 10 deletions src/segment_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ func (pt *path) string() string {
var formattedPath string
switch style := pt.props.getString(Style, Agnoster); style {
case Agnoster:
formattedPath = pt.getAgnosterPath(cwd)
formattedPath = pt.getAgnosterPath()
case AgnosterFull:
formattedPath = pt.getAgnosterFullPath(cwd)
formattedPath = pt.getAgnosterFullPath()
case AgnosterShort:
formattedPath = pt.getAgnosterShortPath(cwd)
formattedPath = pt.getAgnosterShortPath()
case Short:
// "short" is a duplicate of "full", just here for backwards compatibility
fallthrough
case Full:
formattedPath = pt.getFullPath(cwd)
formattedPath = pt.getFullPath()
case Folder:
formattedPath = pt.getFolderPath(cwd)
formattedPath = pt.getFolderPath()
default:
return fmt.Sprintf("Path style: %s is not available", style)
}
Expand All @@ -77,8 +77,9 @@ func (pt *path) init(props *properties, env environmentInfo) {
pt.env = env
}

func (pt *path) getAgnosterPath(pwd string) string {
func (pt *path) getAgnosterPath() string {
buffer := new(bytes.Buffer)
pwd := pt.getPwd()
buffer.WriteString(pt.rootLocation())
pathDepth := pt.pathDepth(pwd)
for i := 1; i < pathDepth; i++ {
Expand All @@ -90,18 +91,20 @@ func (pt *path) getAgnosterPath(pwd string) string {
return buffer.String()
}

func (pt *path) getAgnosterFullPath(pwd string) string {
func (pt *path) getAgnosterFullPath() string {
pwd := pt.getPwd()
if string(pwd[0]) == pt.env.getPathSeperator() {
pwd = pwd[1:]
}
return pt.replaceFolderSeparators(pwd)
}

func (pt *path) getAgnosterShortPath(pwd string) string {
func (pt *path) getAgnosterShortPath() string {
pathSeparator := pt.env.getPathSeperator()
folderSeparator := pt.props.getString(FolderSeparatorIcon, pathSeparator)
folderIcon := pt.props.getString(FolderIcon, "..")
root := pt.rootLocation()
pwd := pt.getPwd()
base := base(pwd, pt.env)
pathDepth := pt.pathDepth(pwd)
if pathDepth <= 0 {
Expand All @@ -113,11 +116,13 @@ func (pt *path) getAgnosterShortPath(pwd string) string {
return fmt.Sprintf("%s%s%s%s%s", root, folderSeparator, folderIcon, folderSeparator, base)
}

func (pt *path) getFullPath(pwd string) string {
func (pt *path) getFullPath() string {
pwd := pt.getPwd()
return pt.replaceFolderSeparators(pwd)
}

func (pt *path) getFolderPath(pwd string) string {
func (pt *path) getFolderPath() string {
pwd := pt.getPwd()
return base(pwd, pt.env)
}

Expand Down

0 comments on commit e48ec5f

Please sign in to comment.