Skip to content

Instantly share code, notes, and snippets.

@didrocks
Created August 16, 2017 15:42
Show Gist options
  • Save didrocks/1fdbe995b2694c78d1ee37f6ce77d85e to your computer and use it in GitHub Desktop.
Save didrocks/1fdbe995b2694c78d1ee37f6ce77d85e to your computer and use it in GitHub Desktop.
Convert in batch icons and symlinks using bzr
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)
func main() {
filepath.Walk(os.Args[1], func(p string, fi os.FileInfo, err error) error {
if fi.IsDir() {
return nil
}
if !strings.Contains(p, "battery") {
return nil
}
if fi.Mode()&os.ModeSymlink == 0 {
renameFileViaBzr(p)
return nil
}
dest, err := os.Readlink(p)
if err != nil {
fmt.Println("ERRRRRRRRRRr:", err)
}
renameFileViaBzr(p)
newp := goNewName(p)
os.Remove(newp)
os.Symlink(filepath.Base(goNewName(dest)), newp)
return nil
})
}
func renameFileViaBzr(p string) {
exec.Command("bzr", "mv", p, goNewName(p)).Run()
}
func goNewName(p string) string {
s := strings.Split(p, "/")
s[len(s)-1] = "unity-" + s[len(s)-1]
return strings.Join(s, "/")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment