14 Commits

Author SHA1 Message Date
6b4d131f4f Updated README and TODO 2024-08-25 15:35:48 -04:00
51b4029a79 Changed project name to include repo path 2024-08-25 15:30:40 -04:00
a1f804ac38 Used absolute import path 2024-08-25 15:30:23 -04:00
eb32ec1027 Added link to releases 2024-08-15 12:55:32 -05:00
2625239dba Added note describing where to obtain releases 2024-08-15 12:53:24 -05:00
44de668546 Updated README 2024-08-15 12:46:01 -05:00
20cb665b33 Updated README 2024-08-15 12:45:43 -05:00
9a6fc3475a Added comment to function 2024-08-15 12:42:50 -05:00
d15a771e89 Removed references to Windows support
The program doesn't seem to work on Windows, and I don't have the time
right now to debug it. So, at the moment, the program isn't supported on Windows.
2024-08-15 12:37:01 -05:00
f8cb03bf88 Wrote script to create release builds 2024-08-15 12:28:12 -05:00
b65cef96c3 Replaced the relative path on Windows with an absolute path 2024-08-15 12:27:48 -05:00
b511c14cc3 Updated gitignore 2024-08-15 12:27:33 -05:00
122cd5ed04 Fixed typo 2024-08-15 11:38:00 -05:00
3b8bcb4c8a Updated README 2024-08-15 11:37:13 -05:00
7 changed files with 53 additions and 31 deletions

1
.gitignore vendored
View File

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

View File

@@ -5,27 +5,47 @@ ccat is a file printing tool (like 'cat') which uses Regular Expressions to enab
--- ---
### Features ### Features
- 11 colors out-of-the-box: Red, Blue, Green, Magenta, Cyan, Black, White, Yellow, Gray, Orange and Dark Blue. - 11 colors are defined out-of-the-box: RED, BLUE, GREEN, MAGENTA, CYAN, BLACK, WHITE, YELLOW, GRAY, ORANGE and DARKBLUE.
- Support for defining custom colors via the `ccat.colors` file. - Support for defining custom colors via the `ccat.colors` file.
- Regex-color mappings are stored in configuration files. - Regex-color mappings are stored in configuration files.
- Uses the file extension to determine which configuration file to use. - Uses the file extension to determine which configuration file to use.
- 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.
- Cross-platform - Linux and MacOS supported.
--- ---
### Installing ### Installing
Download the appropriate zip-file from the 'Releases' section. Place the executable in your PATH.
NOTE: The releases are not available on the GitHub repo (which is a mirror of https://gitea.twomorecents.org/Rockingcool/ccat). Obtain the [releases](https://gitea.twomorecents.org/Rockingcool/ccat/releases) from there instead.
---
### Building from source
If you have the `go` command installed, run `make` after cloning the repository. If you have the `go` command installed, run `make` after cloning the repository.
--- ---
### Supported Languages
The following languages have config files included by default:
- C
- Go
---
### Getting Started ### Getting Started
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. 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.
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.
For example, if you want to create syntax highlighting for Java, create a file named `java.conf` in your config directory. In this file, include regular-expressions for each of the langauges's keywords, and provide a corresponding color. Use the provided `c.conf` and `go.conf` files as a starting point.
--- ---
### Config Files ### Config Files
@@ -49,5 +69,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.

View File

@@ -1,12 +1,11 @@
package main package main
import ( import (
"ccat/stack"
"embed" "embed"
"errors" "errors"
"gitea.twomorecents.org/Rockingcool/ccat/stack"
"io/fs" "io/fs"
"os" "os"
"os/user"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
@@ -18,27 +17,18 @@ 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 a directory. // be outputted into the given directory.
// //
// If there is an error encountered, the error is returned. // If there is an error encountered, the error is returned.
func generateDefaultConfigs() error { func generateDefaultConfigs(configOutputPath string) 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) {

17
create_release_builds.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/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

2
go.mod
View File

@@ -1,4 +1,4 @@
module ccat module gitea.twomorecents.org/Rockingcool/ccat
go 1.22.5 go 1.22.5

11
main.go
View File

@@ -78,18 +78,13 @@ 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.
var configPath string // Location of config files, depends on OS currentUser, err := user.Current() // Get current user, to determine config path
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() generateDefaultConfigs(configPath)
} }
// Check if user has provided a file name // Check if user has provided a file name

View File

@@ -1,5 +1,4 @@
1. Man page 1. Man page
2. README for GitHub Repo
2. Logging 2. Logging
3. Coloring functions 3. Coloring functions
4. Flag to list all available colors for your terminal - some terminals will only support the predefined colors. 4. Flag to list all available colors for your terminal - some terminals will only support the predefined colors.