-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from essentialkaos/develop
Version 1.7.4
- Loading branch information
Showing
4 changed files
with
153 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// +build !darwin !linux | ||
// +build windows | ||
|
||
package fsutil | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// +build !windows | ||
|
||
package fsutil | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2009-2016 Essential Kaos // | ||
// Essential Kaos Open Source License <http://essentialkaos.com/ekol?en> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
var dirStack []string | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
// Push change current working directory and add previous working directory to stack | ||
func Push(dir string) string { | ||
if dirStack == nil { | ||
dirStack = append(dirStack, Current()) | ||
} | ||
|
||
err := os.Chdir(dir) | ||
|
||
if err != nil { | ||
return "" | ||
} | ||
|
||
wd, _ := os.Getwd() | ||
|
||
dirStack = append(dirStack, wd) | ||
|
||
return wd | ||
} | ||
|
||
// Pop change current working directory to previous in stack | ||
func Pop() string { | ||
if dirStack == nil { | ||
dirStack = append(dirStack, Current()) | ||
} | ||
|
||
dl := len(dirStack) | ||
|
||
switch dl { | ||
|
||
case 0, 1: | ||
// nop | ||
|
||
default: | ||
err := os.Chdir(dirStack[dl-2]) | ||
|
||
if err != nil { | ||
return "" | ||
} | ||
|
||
dirStack = dirStack[0 : dl-1] | ||
} | ||
|
||
wd, _ := os.Getwd() | ||
|
||
return wd | ||
} | ||
|
||
// Current return current working directory | ||
func Current() string { | ||
wd, err := os.Getwd() | ||
|
||
if err != nil { | ||
return "" | ||
} | ||
|
||
return wd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// +build windows | ||
|
||
package fsutil | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2009-2016 Essential Kaos // | ||
// Essential Kaos Open Source License <http://essentialkaos.com/ekol?en> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
func Push(dir string) string { | ||
return "" | ||
} | ||
|
||
// Pop change current working directory to previous in stack | ||
func Pop() string { | ||
return "" | ||
} | ||
|
||
// Current return current working directory | ||
func Current() string { | ||
return "" | ||
} |