Compare commits

..

No commits in common. '9a6fc3475a00e595a4371296c4e92f477f7e94bd' and '122cd5ed041c8c851a2ae3086b1bbfa4f0c74978' have entirely different histories.

1
.gitignore vendored

@ -1,3 +1,2 @@
ccat ccat
*.zip

@ -12,7 +12,7 @@ ccat is a file printing tool (like 'cat') which uses Regular Expressions to enab
- Highly extensible - to add a config file for an specific file type, name the file `<extension>.conf`. - Highly extensible - to add a config file for an specific file type, name the file `<extension>.conf`.
- Support for printing line numbers with the `-n` flag. - Support for printing line numbers with the `-n` flag.
- Statically linked Go binary - no runtime dependencies, config files are distributed along with the binary. - Statically linked Go binary - no runtime dependencies, config files are distributed along with the binary.
- Linux and MacOS supported. - Cross-platform
--- ---
@ -32,7 +32,7 @@ The following languages have config files included by default:
--- ---
### Getting Started ### Getting Started
The config files are embedded within the binary. They will automatically be installed to the correct location (`~/.config/ccat` on UNIX) when the program is first run. The config files are embedded within the binary. They will automatically be installed to the correct location (`%APPDATA/ccat` on Windows, `~/.config/ccat` on UNIX) when the program is first run.
As written above, if provided a file with extension `.example`, the program will look for the config file named `example.conf`. If such a file doesn't exist, the file is printed out without any highlighting. As written above, if provided a file with extension `.example`, the program will look for the config file named `example.conf`. If such a file doesn't exist, the file is printed out without any highlighting.
@ -61,6 +61,5 @@ Note that the color name must be capitalized (and shouldn't contain spaces). The
--- ---
### TODO: ### TODO:
- Windows support.
- Allow users to provide a config file in the command-line, overriding the extension-based config file. - Allow users to provide a config file in the command-line, overriding the extension-based config file.
- Provide releases. - Provide releases.

@ -6,6 +6,7 @@ import (
"errors" "errors"
"io/fs" "io/fs"
"os" "os"
"os/user"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
@ -17,18 +18,27 @@ import (
//go:embed config //go:embed config
var storedConfigs embed.FS // Embed the folder containing config files var storedConfigs embed.FS // Embed the folder containing config files
// runningOnWindows: At the moment this function isn't used. When Window support is added,
// it will be used to determine if the program is being run on Windows.
func runningOnWindows() bool { func runningOnWindows() bool {
return runtime.GOOS == "windows" return runtime.GOOS == "windows"
} }
// generateDefaultConfigs is used to generate a folder of default config files // generateDefaultConfigs is used to generate a folder of default config files
// for common languages. These default config files are embedded into the program, and will // for common languages. These default config files are embedded into the program, and will
// be outputted into the given directory. // be outputted into a directory.
// //
// If there is an error encountered, the error is returned. // If there is an error encountered, the error is returned.
func generateDefaultConfigs(configOutputPath string) error { func generateDefaultConfigs() error {
var configOutputPath string // Location of config files, depends on OS
if runningOnWindows() {
configOutputPath = "%APPDATA%\\ccat"
} else {
currentUser, err := user.Current()
if err != nil {
panic(err)
}
configOutputPath = filepath.Join("/home/" + currentUser.Username + "/.config/ccat/")
}
err := os.MkdirAll(configOutputPath, 0755) err := os.MkdirAll(configOutputPath, 0755)
if err != nil { if err != nil {
if os.IsExist(err) { if os.IsExist(err) {

@ -1,17 +0,0 @@
#!/bin/bash
set -euo pipefail
POSSIBLE_GOOS=( "linux" "darwin" )
POSSIBLE_GOARCH=( "amd64" "arm64" )
for OS in "${POSSIBLE_GOOS[@]}"; do
for ARCH in "${POSSIBLE_GOARCH[@]}"; do
FOLDER_NAME="ccat-$OS-$ARCH"
mkdir "${FOLDER_NAME}"
GOOS=$OS GOARCH=$ARCH go build -o "${FOLDER_NAME}/"
zip -r "${FOLDER_NAME}" "${FOLDER_NAME}"
rm -r "${FOLDER_NAME}"
done
done

@ -78,13 +78,18 @@ func main() {
flag.Parse() flag.Parse()
// Check if config exists. If it doesn't, generate the config files. // Check if config exists. If it doesn't, generate the config files.
currentUser, err := user.Current() // Get current user, to determine config path var configPath string // Location of config files, depends on OS
if runningOnWindows() {
configPath = "%APPDATA%\\ccat"
} else {
currentUser, err := user.Current()
if err != nil { if err != nil {
panic(err) panic(err)
} }
configPath := filepath.Join("/home/" + currentUser.Username + "/.config/ccat/") configPath = filepath.Join("/home/" + currentUser.Username + "/.config/ccat/")
}
if _, err := os.Stat(configPath); os.IsNotExist(err) { if _, err := os.Stat(configPath); os.IsNotExist(err) {
generateDefaultConfigs(configPath) generateDefaultConfigs()
} }
// Check if user has provided a file name // Check if user has provided a file name

Loading…
Cancel
Save