Skip to content

Commit

Permalink
Rewrite symlink generator with go
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Jul 28, 2023
1 parent 9cc4642 commit 145d102
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
.config/fish/config.fish

dist/
tmp/
7 changes: 6 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ args = [
'./cmd/print-deps',
]

[tasks.prepare-build]
command = 'mkdir'
args = ['-p', 'dist']

[tasks.test-race]
dependencies = ['prepare-build']
command = 'go'
args = [
'build',
'-v',
'-race',
'-o',
'dist/print-deps',
'dist',
'./...',
]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you backed to 🚼 from some reasons, See [Wiki](https://github.com/kachick/d
1. Install [nix-community/home-manager](https://github.com/nix-community/home-manager)
1. Set `XDG_*` into current env. `. ./home/.bashrc`
1. Make sure `$XDG_CONFIG_HOME/home-manager/home.nix` does not exists. If not, check the content and remove
1. `./scripts/make_symlinks.bash`
1. Run `go run ./cmd/mksym --linker path-from --linked path-to` if needed
1. `home-manager switch`
1. (optional) Install [jdxcode/rtx](https://github.com/jdxcode/rtx) to manage subdivided versions

Expand Down
48 changes: 48 additions & 0 deletions cmd/mksym/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"flag"
"log"
"os"
"path/filepath"
)

func main() {
linkerFlag := flag.String("linker", "", "path - from")
linkedFlag := flag.String("linked", "", "path - to")

flag.Parse()

linker := *linkerFlag
linked := *linkedFlag

if linker == "" || linked == "" {
flag.Usage()
log.Fatalln("empty path is given")
}

linked, err := filepath.Abs(linked)
if err != nil {
log.Fatalln(err)
}

_, err = os.Stat(linked)
if err != nil {
log.Fatalf("target does not exist, fix `linked` option - %v\n", err)
}
_, err = os.Stat(linker)
if err == nil || !os.IsNotExist(err) {
log.Fatalf("this script does not override existing symlinker files, fix `linker` option or manually remove the file - %v\n", err)
}

parent := filepath.Dir(linker)
err = os.MkdirAll(parent, 0755)
if err != nil {
log.Fatalln(err)
}

err = os.Symlink(linked, linker)
if err != nil {
log.Fatalln(err)
}
}
6 changes: 0 additions & 6 deletions scripts/make_symlink.bash

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/make_symlinks.bash

This file was deleted.

0 comments on commit 145d102

Please sign in to comment.