Skip to content

Commit

Permalink
Initial commit 2024 █▁▁▁▁▁▁▁▁▁ 18.95%
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsirbe committed Mar 10, 2024
0 parents commit 0641e0e
Show file tree
Hide file tree
Showing 11 changed files with 415 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: goreleaser
on:
push:
tags:
- '*'
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: ${{ env.GITHUB_REF_NAME }}
args: release --clean --release-notes=./RELEASE.md
distribution: goreleaser
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PUBLISHER_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/update-description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Update repo description
on:
schedule:
- cron: '0 */6 * * *'
workflow_dispatch:
jobs:
update-description:
runs-on: macos-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install yp
run: brew install martinsirbe/clinkclank/yp
- name: Generate repo description
id: generate-description
run: |
description=$(yp -t 10)" 👈 Progressing through "$(date +"%Y")", a simple Go app that displays the current year's progress through a dynamic progress bar, reflecting the percentage of the year elapsed."
echo "DESCRIPTION=$description" >> $GITHUB_ENV
- name: Update repo description
uses: octokit/[email protected]
with:
route: PATCH /repos/${{ github.repository }}
description: ${{ env.DESCRIPTION }}
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PUBLISHER_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
./yp
52 changes: 52 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: 1
project_name: yp
before:
hooks:
- go mod tidy
builds:
- main: ./cmd/yp
binary: yp
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
release:
prerelease: auto
universal_binaries:
- replace: true
brews:
- name: yp
description: "Year Progress Indicator"
homepage: "https://github.com/martinsirbe/go-year-progress"
repository:
owner: martinsirbe
name: homebrew-clinkclank
commit_author:
name: martinsirbe
email: [email protected]
caveats: |
Thank you for installing the Year Progress Indicator (yp)! Here are some tips to get started:
## Configuration and Usage
- Run `yp` in any terminal to see how much of the current year has elapsed, represented through a visually appealing progress bar.
- Customise the appearance of your progress bar with CLI options or environment variables for a personalized touch:
- Use CLI options like `--location` to set your timezone or `--total-blocks` to adjust the progress bar's length.
- Alternatively, set environment variables such as `YP_LOCATION` and `YP_TOTAL_BLOCKS` for persistent configurations.
## Integration Ideas
- **Terminal Welcome Message**: Enhance your terminal sessions by adding `yp` to your shell's profile (e.g., `.bashrc`, `.zshrc`), so you can visualize the year's progress with every new terminal window.
- **GitHub README**: Make your project README stand out by including the year's progress bar.
- **Daily Logs/Journals**: Incorporate the progress bar in your digital or printed logs as a unique way to track the passage of time.
- **Personal Websites**: Share the year's progression with visitors by integrating the tool's output into your site.
For more details on options and configurations, run `yp --help` or check the GitHub repository: https://github.com/martinsirbe/yp
Enjoy visualising the passage of time with yp, and feel free to contribute to its development!
test: |
system "#{bin}/yp", "--help"
checksum:
name_template: 'checksums.txt'
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2024 Martins Irbe

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.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: build
build:
go build -o yp cmd/yp/main.go

.PHONY: release-local
release-local:
goreleaser release --snapshot --skip-publish --clean --rm-dist
101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
The Year Progress Indicator is a Go application that visually represents how much of the current year has elapsed.
It calculates the percentage of the year that has passed based on today's date and displays this information through
a progress bar composed of filled and unfilled segments. This utility is designed for those who would like to visualise
the passage of time throughout the year.

# Features

- **Automatic Date Calculation**: Dynamically computes the current date to determine the year's elapsed portion.
- **Leap Year Handling**: Accurately accounts for leap years in day counts.
- **Visual Progress Display**: Utilises `` for the elapsed part of the year and `` for what remains, complemented by a percentage display.

# Use Cases

- **Terminal Welcome Message**: Add the `yp` command to your shell's profile file (e.g., `.bashrc` or `.zshrc`) to see the year's progress every time you open a new terminal window.
- **GitHub README**: Include the progress bar in your project's README.md to show the year's progress in a creative way.
- **Daily Logs/Journals**: Include the year's progress in digital or printed daily logs to visualize how much of the year has passed.
- **Project Milestones**: Use the progress indicator to track the passage of time relative to project deadlines or milestones.
- **Personal Websites**: Incorporate the tool's output into a personal or professional website to share the year's progression with visitors.

# Installation

For convenience, pre-built binaries are available for various platforms. Download the appropriate binary for your system from the releases page.

## Homebrew

To install the Year Progress Indicator using Homebrew on macOS or Linux, you can follow these steps:

```shell
brew tap martinsirbe/clinkclank
brew install martinsirbe/clinkclank/yp
```

This will add the custom tap and install the `yp` CLI, making it readily accessible from any terminal.

## Build from Source
Make sure you have Go installed. You can then install the Year Progress Indicator globally via the following command:

```shell
go install github.com/martinsirbe/go-year-progress/cmd/[email protected]
```

This command compiles and installs the binary to your Go bin directory, making it accessible from any terminal provided the directory is in your system's PATH.

# Usage

Run the tool from any terminal with `yp`.

# Configuration

You can configure the application using CLI options or by setting environment variables. This flexibility allows you to choose the most convenient method for your workflow.

## CLI Options

You can specify the following options directly through the command line:

* `-e`, `--empty-char` - Character for empty sections of the progress bar (default "▁")
* `-f`, `--filled-char` - Character for filled sections of the progress bar (default "█")
* `-l`, `--location` - Timezone location for accurate time display (default "UTC")
* `-t`, `--total-blocks` - Total number of blocks in the progress bar (default 50)

## Environment Variables

As an alternative to CLI options, you can set the following environment variables. These are particularly useful for persistent configurations or for contexts where command-line arguments may not be ideal:

* `YP_LOCATION` - Overrides the default timezone location.
* `YP_TOTAL_BLOCKS` - Sets the total number of blocks in the progress bar.
* `YP_FILLED_CHAR` - Specifies the character for filled sections of the progress bar.
* `YP_EMPTY_CHAR` - Specifies the character for empty sections of the progress bar.

## Example Outputs

Without any configuration, the output will look like this:
```
███████▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ 15.18%
```

### Using CLI Options

To customise the progress bar with CLI options, you might use the following command:
```shell
yp --location "America/New_York" --total-blocks 30 --filled-char "x" --empty-char "-"
```

### Using Environment Variables
Alternatively, you can achieve the same customisation by setting environment variables:
```shell
YP_LOCATION="America/New_York" YP_TOTAL_BLOCKS=30 YP_FILLED_CHAR="x" YP_EMPTY_CHAR="-" yp
```

Both of the above configurations adjust the progress bar to reflect a timezone of "America/New_York", a total of 30 blocks, with "x" representing filled sections and "-" for empty ones. The resulting output, assuming a similar progress of 15.18% UTC, would be:
```shell
xxxx-------------------------- 15.13%
```

# Contributing

Feel free to contribute to the project by submitting pull requests or creating issues for bugs and feature requests.

# License

This project is licensed under the MIT License. See [LICENSE.md](LICENSE.md).
6 changes: 6 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Features

* **Automatic Date Calculation**: Dynamically computes the current date to determine the year's elapsed portion.
* **Leap Year Handling**: Accurately accounts for leap years in day counts.
* **Visual Progress Display**: Utilises `` for the elapsed part of the year and `` for what remains, complemented by a percentage display.
* **Customisable Configuration**: The appearance and behaviour of the year progress bar can be customised through CLI options or environment variables, allowing for personalised settings for location, total blocks, and character representation of filled and empty sections.
82 changes: 82 additions & 0 deletions cmd/yp/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package main

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var rootCmd = &cobra.Command{
Use: "yp",
Short: "Year Progress Indicator",
Long: `The Year Progress Indicator is a Go application that visually represents how much of the current year has elapsed.
It calculates the percentage of the year that has passed based on today's date and displays this information through
a progress bar composed of filled and unfilled segments.`,
Run: func(cmd *cobra.Command, args []string) {
runYearProgress()
},
}

func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringP("location", "l", "UTC", "Timezone location")
rootCmd.PersistentFlags().IntP("total-blocks", "t", 50, "Total number of blocks in the progress bar")
rootCmd.PersistentFlags().StringP("filled-char", "f", "█", "Character for filled sections of the progress bar")
rootCmd.PersistentFlags().StringP("empty-char", "e", "▁", "Character for empty sections of the progress bar")

viper.BindPFlag("location", rootCmd.PersistentFlags().Lookup("location"))
viper.BindPFlag("total_blocks", rootCmd.PersistentFlags().Lookup("total-blocks"))
viper.BindPFlag("filled_char", rootCmd.PersistentFlags().Lookup("filled-char"))
viper.BindPFlag("empty_char", rootCmd.PersistentFlags().Lookup("empty-char"))
}

func initConfig() {
viper.SetEnvPrefix("yp")
viper.AutomaticEnv()
viper.ReadInConfig()
}

func runYearProgress() {
location := viper.GetString("location")
totalBlocks := viper.GetInt("total_blocks")
filledChar := viper.GetString("filled_char")
emptyChar := viper.GetString("empty_char")

loc, err := time.LoadLocation(location)
if err != nil {
fmt.Printf("Failed to load location: %s\n", err)
return
}

now := time.Now().In(loc)
startOfYear := time.Date(now.Year(), 1, 1, 0, 0, 0, 0, loc)
endOfYear := time.Date(now.Year(), 12, 31, 23, 59, 59, 0, loc)
totalDays := endOfYear.Sub(startOfYear).Hours() / 24
daysElapsed := now.Sub(startOfYear).Hours() / 24
progress := (daysElapsed / totalDays) * 100

progressBar := ""

filledBlocks := int((progress / 100) * float64(totalBlocks))
for i := 0; i < filledBlocks; i++ {
progressBar += filledChar
}

emptyBlocks := totalBlocks - filledBlocks
for i := 0; i < emptyBlocks; i++ {
progressBar += emptyChar
}

fmt.Printf("%s %.2f%%\n", progressBar, progress)
}

func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
31 changes: 31 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module github.com/martinsirbe/go-year-progress

go 1.22

require (
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
)

require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 0641e0e

Please sign in to comment.