commit 1d46a2382482b7cabfaf4e16d048f86ee157f0b2 Author: bruno Date: Tue Jul 25 14:29:22 2023 -0400 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/config.json b/config.json new file mode 100644 index 0000000..80dc7a4 --- /dev/null +++ b/config.json @@ -0,0 +1,23 @@ +{ + "apps": [ + { + "name": "neovim", + "shortcuts": { + "ctrl+alt+n": "Open neovim", + "ctrl+n": "Split neovim horizontally" + } + }, + { + "name": "vscode", + "shortcuts": { + "ctrl+shift+p": "Command palette" + } + }, + { + "name": "Kitty", + "shortcuts": { + "ctrl+shift+e": "Open new terminal" + } + } + ] +} \ No newline at end of file diff --git a/scut b/scut new file mode 100755 index 0000000..69c95ae Binary files /dev/null and b/scut differ diff --git a/scut.go b/scut.go new file mode 100644 index 0000000..0a82f04 --- /dev/null +++ b/scut.go @@ -0,0 +1,61 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "io/ioutil" +) + +type App struct { + Name string `json:"name"` + Shortcuts map[string]string `json:"shortcuts"` +} + +type Config struct { + Apps []App `json:"apps"` +} + +func main() { + + flag.Usage = func() { + fmt.Println("") + fmt.Println("- -- - -- - -- - -- - -- - -- - -- - --") + fmt.Println("Scut-Reminder : Gestion des raccourcis") + fmt.Println("- -- - -- - -- - -- - -- - -- - -- - --") + fmt.Println("Options :") + fmt.Printf(" -c NomDuFichierConfig Utiliser ce fichier de configuration au lieu de config.json (par défaut)\n") + fmt.Printf(" -a Nom Application Afficher les raccourcis de l'application spécifiée\n") + fmt.Printf(" -h Afficher cette aide\n") + fmt.Println("") + fmt.Println("Example :") + fmt.Printf(" scut // Affiche la liste des applications\n\n") + fmt.Printf(" scut -c MaConfig.json -a \"nevim\" // Affiche liste des raccourcis de nevim de MaConfig.json \n\n") + fmt.Printf(" scut -a \"Visual Studio Code\" //Affiche liste des raccourcis de vscode \n\n") + fmt.Println("") + } + + configFile := flag.String("c", "config.json", "Config file") + appName := flag.String("a", "", "Application name") + flag.Parse() + + data, _ := ioutil.ReadFile(*configFile) + var config Config + json.Unmarshal(data, &config) + + if *appName == "" { + // List all applications + for _, app := range config.Apps { + fmt.Printf("%s\n", app.Name) + } + } else { + // List shortcuts for application + for _, app := range config.Apps { + if app.Name == *appName { + for shortcut, desc := range app.Shortcuts { + fmt.Printf("%s: %s\n", shortcut, desc) + } + } + } + } +}