Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
434c804b08 | |||
50d9126f2b | |||
6b4d131f4f | |||
51b4029a79 | |||
a1f804ac38 | |||
eb32ec1027 | |||
2625239dba | |||
44de668546 | |||
20cb665b33 | |||
9a6fc3475a | |||
d15a771e89 | |||
f8cb03bf88 | |||
b65cef96c3 | |||
b511c14cc3 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
ccat
|
||||
*.zip
|
||||
|
||||
|
8
LICENSE.md
Normal file
8
LICENSE.md
Normal file
@@ -0,0 +1,8 @@
|
||||
Copyright 2025 Aadhavan Srinivasan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
16
README.md
16
README.md
@@ -12,11 +12,20 @@ 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`.
|
||||
- Support for printing line numbers with the `-n` flag.
|
||||
- Statically linked Go binary - no runtime dependencies, config files are distributed along with the binary.
|
||||
- Cross-platform
|
||||
- Linux and MacOS supported.
|
||||
|
||||
---
|
||||
|
||||
### 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.
|
||||
|
||||
---
|
||||
@@ -27,12 +36,11 @@ The following languages have config files included by default:
|
||||
|
||||
- C
|
||||
- Go
|
||||
-
|
||||
|
||||
---
|
||||
|
||||
### 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.
|
||||
|
||||
@@ -61,5 +69,5 @@ Note that the color name must be capitalized (and shouldn't contain spaces). The
|
||||
---
|
||||
|
||||
### TODO:
|
||||
- Windows support.
|
||||
- Allow users to provide a config file in the command-line, overriding the extension-based config file.
|
||||
- Provide releases.
|
||||
|
20
config.go
20
config.go
@@ -1,12 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"ccat/stack"
|
||||
"embed"
|
||||
"errors"
|
||||
"gitea.twomorecents.org/Rockingcool/ccat/stack"
|
||||
"io/fs"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
@@ -18,27 +17,18 @@ import (
|
||||
//go:embed config
|
||||
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 {
|
||||
return runtime.GOOS == "windows"
|
||||
}
|
||||
|
||||
// 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
|
||||
// be outputted into a directory.
|
||||
// be outputted into the given directory.
|
||||
//
|
||||
// If there is an error encountered, the error is returned.
|
||||
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/")
|
||||
}
|
||||
func generateDefaultConfigs(configOutputPath string) error {
|
||||
err := os.MkdirAll(configOutputPath, 0755)
|
||||
if err != nil {
|
||||
if os.IsExist(err) {
|
||||
|
@@ -10,11 +10,13 @@
|
||||
# Strings in double quotes and single quotes
|
||||
'"(.*?)"': BLUE
|
||||
"'(.)'": BLUE
|
||||
# Text inside angle-brackets (used in 'include' statements)
|
||||
'\<(.*?)\>': BLUE
|
||||
# Assignments and comparisons
|
||||
# TODO: Add less than, greater than, not equal to, and struct pointer member access
|
||||
'(?:\s|\b)(=|==|!=|<=|>=|\->)(\s|\b)' : CYAN
|
||||
# Keywords
|
||||
'\b(if|else|while|do|for|return)\b': CYAN
|
||||
'^(#ifdef|#ifndef|#define|#include)\b': CYAN
|
||||
'(\n|^)(#ifdef|#ifndef|#define|#include)\b': CYAN
|
||||
# Data Types
|
||||
'\b(int|char|float|double|void|long|short|unsigned|signed|bool)\b': YELLOW
|
||||
|
17
create_release_builds.sh
Executable file
17
create_release_builds.sh
Executable 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
2
go.mod
@@ -1,4 +1,4 @@
|
||||
module ccat
|
||||
module gitea.twomorecents.org/Rockingcool/ccat
|
||||
|
||||
go 1.22.5
|
||||
|
||||
|
15
main.go
15
main.go
@@ -78,18 +78,13 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
// Check if config exists. If it doesn't, generate the config files.
|
||||
var configPath string // Location of config files, depends on OS
|
||||
if runningOnWindows() {
|
||||
configPath = "%APPDATA%\\ccat"
|
||||
} else {
|
||||
currentUser, err := user.Current()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
configPath = filepath.Join("/home/" + currentUser.Username + "/.config/ccat/")
|
||||
currentUser, err := user.Current() // Get current user, to determine config path
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
configPath := filepath.Join("/home/" + currentUser.Username + "/.config/ccat/")
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
generateDefaultConfigs()
|
||||
generateDefaultConfigs(configPath)
|
||||
}
|
||||
|
||||
// Check if user has provided a file name
|
||||
|
Reference in New Issue
Block a user