Skip to content

Commit

Permalink
feat: introduce agnoster_full path style
Browse files Browse the repository at this point in the history
resolves #142
  • Loading branch information
JanDeDobbeleer committed Nov 11, 2020
1 parent b98b606 commit ce01ebf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions segment_path.go
Expand Up @@ -23,6 +23,8 @@ const (
WindowsRegistryIcon Property = "windows_registry_icon"
//Agnoster displays a short path with separator icon, this the default style
Agnoster string = "agnoster"
//AgnosterFull displays all the folder names with the folder_separator_icon
AgnosterFull string = "agnoster_full"
//Short displays a shorter path
Short string = "short"
//Full displays the full path
Expand All @@ -39,6 +41,8 @@ func (pt *path) string() string {
switch style := pt.props.getString(Style, Agnoster); style {
case Agnoster:
return pt.getAgnosterPath()
case AgnosterFull:
return pt.getAgnosterFullPath()
case Short:
return pt.getShortPath()
case Full:
Expand Down Expand Up @@ -85,6 +89,16 @@ func (pt *path) getAgnosterPath() string {
return buffer.String()
}

func (pt *path) getAgnosterFullPath() string {
pwd := pt.env.getcwd()
pathSeparator := pt.env.getPathSeperator()
folderSeparator := pt.props.getString(FolderSeparatorIcon, pathSeparator)
if string(pwd[0]) == pathSeparator {
pwd = pwd[1:]
}
return strings.Replace(pwd, pathSeparator, folderSeparator, -1)
}

func (pt *path) inHomeDir(pwd string) bool {
return strings.HasPrefix(pwd, pt.env.homeDir())
}
Expand Down
17 changes: 17 additions & 0 deletions segment_path_test.go
Expand Up @@ -346,6 +346,23 @@ func TestPathDepthOutsideHomeOneLevelDeep(t *testing.T) {
assert.Equal(t, 1, got)
}

func TestGetAgnosterFullPath(t *testing.T) {
pwd := "/usr/location/whatever"
env := new(MockedEnvironment)
env.On("getPathSeperator", nil).Return("/")
env.On("getcwd", nil).Return(pwd)
path := &path{
env: env,
props: &properties{
values: map[Property]interface{}{
FolderSeparatorIcon: " > ",
},
},
}
got := path.getAgnosterFullPath()
assert.Equal(t, "usr > location > whatever", got)
}

func testWritePathInfo(home string, pwd string, pathSeparator string) string {
props := &properties{
values: map[Property]interface{}{
Expand Down

0 comments on commit ce01ebf

Please sign in to comment.