diff --git a/README.md b/README.md index e69de29..feab711 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,50 @@ +# Scut-Reminder + +Scut-Reminder est un petit utilitaire en ligne de commande pour gérer et lister vos raccourcis d'application favoris. + +## Usage + +``` +scut // Affiche la liste des applications +scut -c MaConfig.json -a "nevim" // Affiche liste des raccourcis de nevim de MaConfig.json +scut -a "Visual Studio Code" // Affiche liste des raccourcis de vscode +``` + +## Options + +- `-c NomDuFichierConfig` Utiliser ce fichier de configuration au lieu de `config.json` (par défaut) +- `-a Nom Application` Afficher les raccourcis de l'application spécifiée +- `-h` Afficher l'aide + +## Installation + +Téléchargez le fichier binaire pour votre plateforme à partir de la section Releases. + +Ou bien compilez le code source Go: +``` +go build +``` + +## Configuration + +Le fichier `config.json` doit respecter ce format : + +```json +{ + "apps": [ + { + "name": "neovim", + "shortcuts": { + "ctrl+alt+n": "Open neovim", + "ctrl+n": "Split neovim horizontally" + } + }, + { + "name": "vscode", + "shortcuts": { + "ctrl+shift+p": "Command palette" + } + } + ] +} +``` diff --git a/config.json b/config.json deleted file mode 100644 index 80dc7a4..0000000 --- a/config.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "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/configuration/gnome.json b/configuration/gnome.json new file mode 100644 index 0000000..ba3236b --- /dev/null +++ b/configuration/gnome.json @@ -0,0 +1,41 @@ +{ + "name": "GNOME", + "shortcuts": { + "ctrl+alt+t": "Terminal", + "ctrl+alt+d": "Show Desktop", + "super": "Activities Overview", + "super+a": "Applications", + "super+f": "Files", + "super+t": "Terminal", + "super+l": "Lock Screen", + "super+shift+q": "Log Out", + "super+shift+d": "Show Applications", + "super+page up": "Switch Workspace on the right", + "super+page down": "Switch Workspace on the left", + "super+1-9": "Switch to Workspace 1-9", + "ctrl+alt+arrow": "Switch Workspace", + "ctrl+alt+up": "Maximize Window", + "ctrl+alt+down": "Unmaximize Window", + "alt+tab": "Switch Applications", + "alt+`": "Switch Windows of the Same Application", + "alt+f2": "Run Command", + "ctrl+alt+delete": "Log Out/Power Off/Restart", + "ctrl+c": "Copy", + "ctrl+v": "Paste", + "ctrl+x": "Cut", + "ctrl+z": "Undo", + "ctrl+shift+z": "Redo", + "ctrl+a": "Select All", + "ctrl+f": "Find", + "ctrl+s": "Save", + "ctrl+o": "Open", + "ctrl+n": "New", + "ctrl+p": "Print", + "ctrl+q": "Quit", + "ctrl+w": "Close Window", + "ctrl+shift+w": "Close All Windows", + "ctrl+shift+t": "Reopen Closed Tab/Window", + "ctrl+plus": "Zoom In", + "ctrl+minus": "Zoom Out" + } +} \ No newline at end of file diff --git a/configuration/kitty.json b/configuration/kitty.json new file mode 100644 index 0000000..88ea245 --- /dev/null +++ b/configuration/kitty.json @@ -0,0 +1,40 @@ +{ + "name": "Kitty Terminal", + "shortcuts": { + "Ctrl+Shift+T": "New tab", + "Ctrl+Shift+W": "Close tab", + "Ctrl+Shift+H": "Move focus to left tab", + "Ctrl+Shift+L": "Move focus to right tab", + "Ctrl+Shift+PageUp": "Move to previous tab", + "Ctrl+Shift+PageDown": "Move to next tab", + "Ctrl+Shift+C": "Copy selected text to clipboard", + "Ctrl+Shift+V": "Paste from clipboard", + "Ctrl+Shift+N": "New Kitty instance", + "Ctrl+Shift+Q": "Quit Kitty", + "Ctrl+Shift+R": "Reload configuration file", + "Ctrl+Shift+F": "Find", + "Ctrl+Shift+G": "Find next", + "Ctrl+Shift+J": "Scroll down one line", + "Ctrl+Shift+K": "Scroll up one line", + "Ctrl+Shift+U": "Scroll up one page", + "Ctrl+Shift+D": "Scroll down one page", + "Ctrl+Shift+Home": "Scroll to top", + "Ctrl+Shift+End": "Scroll to bottom", + "Ctrl+Shift+S": "Save session", + "Ctrl+Shift+O": "Open saved session", + "Ctrl+Shift+X": "Clear scrollback buffer", + "Ctrl+Shift+Z": "Toggle zoom", + "Ctrl+Shift+I": "Inspect current terminal", + "Ctrl+Shift+Tab": "Switch to previous window", + "Ctrl+Shift+Num+": "Increase font size", + "Ctrl+Shift+Num-": "Decrease font size", + "Ctrl+Shift+Num*": "Reset font size", + "Ctrl+Shift+Num/": "Toggle ligatures", + "Ctrl+Shift+Num0": "Reset all settings to default", + "Ctrl+Shift+Num1": "Switch to profile 1", + "Ctrl+Shift+Num2": "Switch to profile 2", + "Ctrl+Shift+Num3": "Switch to profile 3", + "Ctrl+Shift+Num4": "Switch to profile 4", + "Ctrl+Shift+Num5": "Switch to profile 5" + } +} \ No newline at end of file diff --git a/configuration/neovim.json b/configuration/neovim.json new file mode 100644 index 0000000..0509c60 --- /dev/null +++ b/configuration/neovim.json @@ -0,0 +1,39 @@ +{ + "name": "Neovim", + "shortcuts": { + "i": "Insert mode", + "esc": "Normal mode", + "gg": "Go to first line", + "G": "Go to last line", + "dd": "Delete current line", + "yy": "Yank/copy current line", + "p": "Paste yanked/cut text", + "u": "Undo", + "Ctrl-r": "Redo", + "w": "Save changes", + "q": "Quit", + "Ctrl-w": "Close current window", + "Ctrl-n": "Open new empty buffer", + "Ctrl-o": "Open last closed buffer", + "Ctrl-^": "Switch between the current and previous buffer", + "Ctrl-]": "Jump to the definition of a symbol", + "Ctrl-t": "Jump back from the definition of a symbol", + "Ctrl-p": "Open fuzzy finder", + "Ctrl-x Ctrl-f": "Open file explorer", + "Ctrl-x Ctrl-b": "Open buffer explorer", + "Ctrl-g": "Show file information", + "Ctrl-a": "Select all", + "Ctrl-v": "Paste in visual mode", + "v": "Enter visual mode", + "V": "Enter line visual mode", + "Ctrl-c": "Copy in visual mode", + "y": "Yank in visual mode", + "d": "Delete in visual mode", + "c": "Change in visual mode", + "r": "Replace in visual mode", + "s": "Substitute in visual mode", + "Ctrl-l": "Clear search highlight", + "n": "Next search result", + "N": "Previous search result" + } +} \ No newline at end of file diff --git a/configuration/vscode.json b/configuration/vscode.json new file mode 100644 index 0000000..f28d3a3 --- /dev/null +++ b/configuration/vscode.json @@ -0,0 +1,41 @@ +{ + "name": "Visual Studio Code", + "shortcuts": { + "Ctrl+Shift+P": "Command Palette", + "Ctrl+Shift+N": "New Window", + "Ctrl+Shift+W": "Close Window", + "Ctrl+Shift+T": "Reopen Closed Editor", + "Ctrl+Tab": "Switch Editor", + "Ctrl+Shift+Tab": "Switch Editor in Reverse Order", + "Ctrl+Shift+M": "Toggle Problems Panel", + "Ctrl+Shift+G": "Toggle Source Control", + "Ctrl+Shift+D": "Toggle Debug", + "Ctrl+Shift+X": "Toggle Extensions", + "Ctrl+Shift+V": "Open Markdown Preview", + "Ctrl+K V": "Open Markdown Preview to the Side", + "Ctrl+Shift+F": "Find in Files", + "Ctrl+F": "Find", + "Ctrl+H": "Replace", + "F12": "Go to Definition", + "Ctrl+F12": "Go to Definition (in the same file)", + "Alt+F12": "Peek Definition", + "Ctrl+Shift+O": "Go to Symbol", + "Ctrl+Shift+M": "Show Problems", + "Ctrl+Shift+J": "Toggle Search Details", + "Ctrl+Shift+D": "Duplicate Line or Selection", + "Alt+Up": "Move Line Up", + "Alt+Down": "Move Line Down", + "Ctrl+Shift+K": "Delete Line", + "Ctrl+D": "Add Selection to Next Find Match", + "Ctrl+K Ctrl+D": "Move Last Selection to Next Find Match", + "Alt+Left": "Go Back", + "Alt+Right": "Go Forward", + "Ctrl+Shift+U": "Change Case", + "Ctrl+K Z": "Toggle Zen Mode", + "Ctrl+K S": "Toggle Editor Group Layout", + "Ctrl+K Ctrl+W": "Close All Editors", + "Ctrl+Shift+E": "Show Explorer", + "Ctrl+Shift+H": "Replace in Workspace", + "Ctrl+K Ctrl+X": "Trim Trailing Whitespace" + } +} \ No newline at end of file diff --git a/package.sh b/package.sh new file mode 100755 index 0000000..062ab70 --- /dev/null +++ b/package.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Build le script scut.go +go build scut.go + +# Créer l'archive zip +zip -r scut.zip scut README.md configuration + +# Renommer l'archive +mv scut.zip scut-$(date +%Y%m%d).zip \ No newline at end of file diff --git a/scut b/scut index 69c95ae..e7512c7 100755 Binary files a/scut and b/scut differ diff --git a/scut-20230725.zip b/scut-20230725.zip new file mode 100644 index 0000000..162e214 Binary files /dev/null and b/scut-20230725.zip differ diff --git a/scut.go b/scut.go index 0a82f04..c94eeb4 100644 --- a/scut.go +++ b/scut.go @@ -5,6 +5,11 @@ import ( "flag" "fmt" "io/ioutil" + "os" + "path/filepath" + "strings" + "text/tabwriter" + "unicode" ) type App struct { @@ -16,46 +21,108 @@ type Config struct { Apps []App `json:"apps"` } +func loadConfig(dir string) Config { + apps := []App{} + + // Ouvre le répertoire config + files, err := ioutil.ReadDir(dir) + if err != nil { + //panic(err) + fmt.Println("Le répertoire config est inexistant !") + os.Exit(1) + } + + // Lis tous les fichiers .json + for _, file := range files { + if filepath.Ext(file.Name()) == ".json" { + data, _ := ioutil.ReadFile(dir + "/" + file.Name()) + var app App + json.Unmarshal(data, &app) + apps = append(apps, app) + } + } + config := Config{ + Apps: apps, + } + return config +} + func main() { + underline := "- -- - -- - -- - -- - -- - -- - -- - -- - -- - --" + 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(underline) + fmt.Println(" Scut-Reminder : Gestion des raccourcis") + fmt.Println(underline) + fmt.Println("\n Options :") + fmt.Println(underline) + fmt.Printf(" -c PathDuDossierConfig || Path du dossier de configuration au lieu du répertoire ./config (par défaut)\n") + fmt.Printf(" -a Nom Application || Afficher les raccourcis de l'application spécifiée\n") + fmt.Printf(" -f fitre || Filtrer les raccourcis qui contiennent le filtre\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(" Example :") + fmt.Println(underline) + 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.Printf(" scut -a \"Kitty\" -f quit || Affiche liste des raccourcis qui contient 'quit' \n\n") fmt.Println("") } - configFile := flag.String("c", "config.json", "Config file") + configDir := flag.String("c", "config", "Config directory") + appName := flag.String("a", "", "Application name") + + filter := flag.String("f", "", "Filter") flag.Parse() - data, _ := ioutil.ReadFile(*configFile) - var config Config - json.Unmarshal(data, &config) + config := loadConfig(*configDir) + + cleanFilter := strings.TrimFunc(*filter, func(r rune) bool { + return !unicode.IsGraphic(r) + }) if *appName == "" { // List all applications + fmt.Println(underline) + fmt.Println(" A P P L I C A T I O N S") + fmt.Println(underline) for _, app := range config.Apps { fmt.Printf("%s\n", app.Name) } + fmt.Println() } 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) + w := tabwriter.NewWriter(os.Stdout, 0, 0, 10, '.', 0) + if *filter != "" { + for _, app := range config.Apps { + if strings.ToUpper(app.Name) == strings.ToUpper(*appName) { + fmt.Println(underline) + fmt.Fprintln(w, " S H O R T C U T S : "+app.Name) + fmt.Println(underline) + for shortcut, desc := range app.Shortcuts { + if strings.Contains(strings.ToUpper(shortcut), strings.ToUpper(cleanFilter)) || strings.Contains(strings.ToUpper(desc), strings.ToUpper(cleanFilter)) { + fmt.Fprintf(w, "%s \t %s\n", shortcut, desc) + } + } } } + w.Flush() + } else { + for _, app := range config.Apps { + if strings.ToUpper(app.Name) == strings.ToUpper(*appName) { + fmt.Println(underline) + fmt.Fprintln(w, " S H O R T C U T S : "+app.Name) + fmt.Println(underline) + for shortcut, desc := range app.Shortcuts { + fmt.Fprintf(w, "%s \t %s\n", shortcut, desc) + } + } + } + w.Flush() } } + }