Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/allow to group projects dirs issue #89 #127

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: goreleaser

on:
push:
tags:
- "*"

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

46 changes: 37 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
project_name: smug

before:
Expand All @@ -6,26 +7,53 @@ before:
builds:
- env:
- CGO_ENABLED=0
ldflags:
- "-X=main.version={{.Env.VERSION}}"
goos:
- linux
- windows
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
"Bitbucket CLI {{ .Version }}"_
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be smug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. It turns out my branch was out of sync from master. I have pushed a new commit

{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
version_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- test
- README

nfpms:
- license: MIT
maintainer: 'Ivaaaan [email protected]'
homepage: https://github.com/ivaaaan/smug
dependencies:
- git
description: Bitbucket client command line tool.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to Session manager and task runner for tmux. Start your development environment within one command. please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry didn't mean to include these files in this PR I will update it

formats:
- deb
- rpm
contents:
- src: ./completion/smug.bash
dst: /usr/share/bash-completion/completions/smug
file_info:
mode: 0644
- src: ./completion/smug.fish
dst: /usr/share/fish/vendor_completions.d/smug.fish
file_info:
mode: 0644

56 changes: 51 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ func setTmuxOptions(tmuxOpts *TmuxOptions, c Config) {
if c.ConfigFile != "" {
usr, err := user.Current()
if err != nil {
log.Fatalf("cannot expand user home dir: %s", err)
log.Fatalf("cannot expand user home dir: %s", err)
}
path := c.ConfigFile
if strings.HasPrefix(path,"~") {
if strings.HasPrefix(path, "~") {
path = filepath.Join(usr.HomeDir, path[1:])
}

Expand Down Expand Up @@ -130,7 +130,7 @@ func ParseConfig(data string, settings map[string]string) (Config, error) {
return c, nil
}

func ListConfigs(dir string) ([]string, error) {
func ListConfigs(dir string, includeDirs bool) ([]string, error) {
var result []string
files, err := os.ReadDir(dir)

Expand All @@ -140,7 +140,12 @@ func ListConfigs(dir string) ([]string, error) {

for _, file := range files {
fileExt := path.Ext(file.Name())
if fileExt != ".yml" && fileExt != ".yaml" {
dirCheck := true
if includeDirs {
dirCheck = !file.IsDir()
}
if fileExt != ".yml" && fileExt != ".yaml" && dirCheck {

continue
}
result = append(result, file.Name())
Expand All @@ -150,7 +155,7 @@ func ListConfigs(dir string) ([]string, error) {
}

func FindConfig(dir, project string) (string, error) {
configs, err := ListConfigs(dir)
configs, err := ListConfigs(dir, false)
if err != nil {
return "", err
}
Expand All @@ -164,3 +169,44 @@ func FindConfig(dir, project string) (string, error) {

return "", ConfigNotFoundError{Project: project}
}
func FindConfigs(dir, project string) ([]string, error) {
isDir, _ := IsDirectory(dir + "/" + project)

if isDir {
configs, err := ListConfigs(dir+"/"+project, false)
if err != nil {
return configs, err
}
for configIndex, configName := range configs {
configs[configIndex] = dir + "/" + project + "/" + configName
}
return configs, err
}

configs, err := ListConfigs(dir, false)
if err != nil {
return configs, err
}

if len(configs) == 0 {
return configs, ConfigNotFoundError{Project: project}
}

for _, config := range configs {
fileExt := path.Ext(config)
if strings.TrimSuffix(config, fileExt) == project {
return []string{dir + "/" + config}, nil
}
}

return configs, ConfigNotFoundError{Project: project}
}

func IsDirectory(path string) (bool, error) {

fileInfo, err := os.Stat(path)
if os.IsNotExist(err) {
return false, err
}
return fileInfo.IsDir(), err
}
65 changes: 49 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ func main() {
if options.Config != "" {
configPath = options.Config
} else if options.Project != "" {

config, err := FindConfig(userConfigDir, options.Project)
if err != nil && options.Command != CommandNew {

if err != nil && options.Command != CommandNew && options.Command != CommandStart && options.Command != CommandStop {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
Expand All @@ -117,35 +119,48 @@ func main() {
} else {
fmt.Println("Starting new windows...")
}

config, err := GetConfig(configPath, options.Settings, smug.tmux.TmuxOptions)
configs, err := FindConfigs(userConfigDir, options.Project)
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
}

err = smug.Start(config, options, context)
if err != nil {
fmt.Println("Oops, an error occurred! Rolling back...")
smug.Stop(config, options, context)
os.Exit(1)
for configIndex, configPath := range configs {
config, err := GetConfig(configPath, options.Settings, smug.tmux.TmuxOptions)
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
}
options.Detach = configIndex != len(configs)-1
err = smug.Start(config, options, context)
if err != nil {
fmt.Println("Oops, an error occurred! Rolling back...")
smug.Stop(config, options, context)
os.Exit(1)
}
}
case CommandStop:
if len(options.Windows) == 0 {
fmt.Println("Terminating session...")
} else {
fmt.Println("Killing windows...")
}
config, err := GetConfig(configPath, options.Settings, smug.tmux.TmuxOptions)
configs, err := FindConfigs(userConfigDir, options.Project)
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
}

err = smug.Stop(config, options, context)
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
for _, configPath := range configs {
config, err := GetConfig(configPath, options.Settings, smug.tmux.TmuxOptions)
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
}

err = smug.Stop(config, options, context)
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
}
}
case CommandNew, CommandEdit:
err := EditConfig(configPath)
Expand All @@ -154,7 +169,7 @@ func main() {
os.Exit(1)
}
case CommandList:
configs, err := ListConfigs(userConfigDir)
configs, err := ListConfigs(userConfigDir, true)
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
Expand All @@ -163,6 +178,24 @@ func main() {
for _, config := range configs {
fileExt := path.Ext(config)
fmt.Println(strings.TrimSuffix(config, fileExt))
isDir, err := IsDirectory(userConfigDir+"/"+config)
if err != nil {
continue
}
if isDir {

subConfigs, err := ListConfigs(userConfigDir+"/"+config, false)
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
}
for _, subConfig := range subConfigs {
fileExt := path.Ext(subConfig)
fmt.Println("|--"+strings.TrimSuffix(subConfig, fileExt))
}

}

}

case CommandPrint:
Expand Down
Loading