Tidy up structure of briefcase

I had a spare fifteen minutes and decided that I should tidy up my
monorepo. The work of tidying up is not finished; this is a small step in the
right direction.

TL;DR
- Created a tools directory
- Created a scratch directory (see README.md for more information)
- Added README.md to third_party
- Renamed delete_dotfile_symlinks -> symlinkManager
- Packaged symlinkManager as an executable symlink-mgr using buildGo
This commit is contained in:
William Carroll 2020-02-12 16:58:29 +00:00
parent 5ec5a6da8c
commit fabf1c9334
89 changed files with 53 additions and 41 deletions

View file

@ -23,6 +23,7 @@ let
gopkgs = readTree ./gopkgs;
monzo_ynab = readTree ./monzo_ynab;
third_party = readTree ./third_party;
tools = readTree ./tools;
};
in fix(self: {
config = config self;

View file

@ -21,6 +21,11 @@ func HomeDir() string {
return user.HomeDir
}
// Returns true if `info` is a symlink.
func IsSymlink(info os.FileMode) bool {
return info&os.ModeSymlink != 0
}
// Return true if `path` exists and false otherwise.
func FileExists(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {

6
scratch/README.md Normal file
View file

@ -0,0 +1,6 @@
# Scratch
The purpose of the `scratch` directory is to host practice exercises. Practice
encompasses things like working on data structures and algorithms problems for
upcoming coding interviews or general aptitude as well as writing code snippets
to help me learn a new programming language or understand an unfamiliar concept.

5
third_party/README.md vendored Normal file
View file

@ -0,0 +1,5 @@
# third_party
The `third_party` directory hosts Nix expressions that package software that I
cannot or have not found in other Nix package repositorys like `nixpkgs` or
`depot`.

View file

@ -0,0 +1,14 @@
# Dotfile Symlink Manager
Find and delete all symlinks to the dotfiles defined in `$BRIEFCASE`.
Oftentimes I corrupt the state of my configuration files. The intention with
this script is to help me clean things up when this happens. An example workflow
might look like:
```shell
> symlink-mgr --audit
> symlink-mgr --seriously
> briefcase # changes directory to $BRIEFCASE
> make install
```

View file

@ -0,0 +1,15 @@
{
depot ? import <depot> {},
briefcase ? import <briefcase> {},
...
}:
depot.buildGo.program {
name = "symlink-mgr";
srcs = [
./main.go
];
deps = with briefcase.gopkgs; [
utils
];
}

View file

@ -1,21 +1,3 @@
// Find and delete all symlinks to the dotfiles defined in $BRIEFCASE.
//
// Oftentimes I corrupt the state of my dotfiles. The intention with this script
// is to write some tooling to help me better manage my dotfile cleanliness. An
// example workflow might look like:
//
// ```shell
// > go run delete_dotfile_symlinks.go --audit
// > go run delete_dotfile_symlinks.go --seriously
// > cd ..
// > make install
// ```
//
// Outstanding TODOs:
// - Package this with <depot>buildGo.nix.
// - How can this be run as script without `go run`? She-bang at the top?
// - See TODOs within this package.
package main
import (
@ -26,25 +8,9 @@ import (
"os"
"path/filepath"
"strings"
"utils"
)
// Wanted for go tooling:
// 1. jump-to-def
// 2. documentation at point
// 3. autocompletion
// TODO: Consider adding this to a utils.go package.
func failOn(err error) {
if err != nil {
log.Fatal(err)
}
}
// TODO: Consider adding this to a utils.go package.
func isSymlink(m os.FileMode) bool {
return m&os.ModeSymlink != 0
}
var hostnames = map[string]string{
os.Getenv("DESKTOP"): "desktop",
os.Getenv("LAPTOP"): "work_laptop",
@ -66,13 +32,13 @@ func main() {
}
home, err := os.UserHomeDir()
failOn(err)
utils.FailOn(err)
count := 0
err = filepath.Walk(home, func(path string, info os.FileInfo, err error) error {
if isSymlink(info.Mode()) {
if utils.IsSymlink(info.Mode()) {
dest, err := os.Readlink(path)
failOn(err)
utils.FailOn(err)
var predicate func(string) bool
@ -80,7 +46,7 @@ func main() {
predicate = func(dest string) bool {
var hostname string
hostname, err = os.Hostname()
failOn(err)
utils.FailOn(err)
seeking, ok := hostnames[hostname]
if !ok {
log.Fatal(fmt.Sprintf("Hostname \"%s\" not supported in the hostnames map.", hostname))
@ -99,14 +65,14 @@ func main() {
} else if *seriously {
fmt.Printf("rm %s\n", path)
err = os.Remove(path)
failOn(err)
utils.FailOn(err)
}
count += 1
}
}
return nil
})
failOn(err)
utils.FailOn(err)
if *audit {
fmt.Printf("Would have deleted %d symlinks.\n", count)
} else if *seriously {