-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 638a80e
Showing
7 changed files
with
445 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
on: | ||
release: | ||
types: | ||
- created | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
CARGO_TERM_COLOR: always | ||
|
||
name: Create Release / Upload Assets | ||
|
||
jobs: | ||
windows: | ||
name: Build for Windows | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up cargo cache | ||
uses: actions/cache@v3 | ||
continue-on-error: false | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: ${{ runner.os }}-cargo- | ||
|
||
- name: Build | ||
run: cargo build --release | ||
|
||
- name: "Move to outputs/ folder" | ||
run: | | ||
mkdir outputs | ||
cp target/release/*.exe outputs/gt-win-x86_64.exe | ||
- name: Upload to temporary storage | ||
uses: actions/upload-artifact@master | ||
with: | ||
name: output-artifact | ||
path: outputs | ||
|
||
linux: | ||
name: Build for Linux | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up cargo cache | ||
uses: actions/cache@v3 | ||
continue-on-error: false | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: ${{ runner.os }}-cargo- | ||
|
||
- name: Build | ||
run: cargo build --release | ||
|
||
- name: Install cargo-deb | ||
run: cargo install cargo-deb | ||
continue-on-error: true | ||
|
||
- name: Create deb package | ||
run: cargo deb | ||
|
||
- name: "Move to outputs/ folder" | ||
run: | | ||
mkdir outputs | ||
cp target/release/gt outputs/gt-linux-x86_64 | ||
cp target/debian/*.deb outputs/gt-linux-x86_64.deb | ||
- name: Upload to temporary storage | ||
uses: actions/upload-artifact@master | ||
with: | ||
name: output-artifact | ||
path: outputs | ||
|
||
macos: | ||
name: Build for Mac | ||
runs-on: macos-11 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up cargo cache | ||
uses: actions/cache@v3 | ||
continue-on-error: false | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: ${{ runner.os }}-cargo- | ||
|
||
- name: Install ARM target | ||
run: rustup update && rustup target add aarch64-apple-darwin | ||
|
||
- name: Build | ||
run: cargo build --release --target=aarch64-apple-darwin | ||
|
||
- name: Build | ||
run: cargo build --release | ||
|
||
# Name of binary needed | ||
- name: "Move to outputs/ folder" | ||
run: | | ||
mkdir outputs | ||
cp target/aarch64-apple-darwin/release/gt outputs/gt-darwin-aarch64 | ||
cp target/release/gt outputs/gt-darwin-x86_64 | ||
- name: Upload to temporary storage | ||
uses: actions/upload-artifact@master | ||
with: | ||
name: output-artifact | ||
path: outputs | ||
|
||
release: | ||
name: Create/or release assets | ||
runs-on: ubuntu-latest | ||
needs: [windows, linux, macos] | ||
|
||
steps: | ||
- name: Download from temporary storage | ||
uses: actions/download-artifact@master | ||
with: | ||
name: output-artifact | ||
path: outputs | ||
|
||
- name: Upload binaries to release | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: outputs/* | ||
tag: ${{ github.ref }} | ||
overwrite: true | ||
file_glob: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "gt" | ||
license = "MIT" | ||
edition = "2021" | ||
version = "0.1.0" | ||
readme = "README.md" | ||
categories = ["command-line-utilities"] | ||
homepage = "https://github.com/fukumone/gt" | ||
repository = "https://github.com/fukumone/gt" | ||
description = "Translate messages from terminal using OpenAI." | ||
authors = ["Toru Fukui <[email protected]>"] | ||
|
||
[dependencies] | ||
clap = { version = "4.1.4", features = ["derive"] } | ||
async-std = "1.12.0" | ||
dotenv = "0.15.0" | ||
reqwest = { version = "0.11", features = ["json"] } | ||
serde = "1.0.152" | ||
serde_derive = "1.0.152" | ||
serde_json = "1.0.91" | ||
tokio = { version = "1", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Toru Fukui | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# gt | ||
The OpenAI GPT model allows for easy access to language translation from the command line with a personal touch. | ||
|
||
## Installation | ||
|
||
You can install gt by running the following command in your terminal. | ||
|
||
``` | ||
curl -fsSL https://raw.githubusercontent.com/fukumone/gt/main/install.sh | sh - | ||
``` | ||
|
||
Or, please download the binary that is compatible with your OS from [here](https://github.com/fukumone/gt/releases/tag/v0.1.0). | ||
|
||
## Usage | ||
|
||
1. Get your API key from OpenAI by setting the `OPENAI_API_KEY` environment variable. Example: `export OPENAI_API_KEY=xxxxx` | ||
For more information, visit the provided [link](https://openai.com/). | ||
|
||
2. To set the language you want to translate to, use the `GT_LANGUAGE` environment variable. For instance, if you want to translate to French, type `export GT_LANGUAGE=French` By default, the GT_LANGUAGE is set to translate to English in any language. | ||
|
||
3. Try it out by opening the command line and typing `gt -t "text"` | ||
|
||
|
||
#### example | ||
``` | ||
# Translated from English to French | ||
$ export GT_LANGUAGE=French | ||
$ gt -t "I love Tokyo greatly, it is wonderful to be here." | ||
# => J'aime Tokyo grandement, c'est merveilleux d'être ici. | ||
# Translated from Spanish to Arabic | ||
$ export GT_LANGUAGE=Arabic | ||
$ gt -t "Me gusta mucho Tokio; es maravilloso estar aquí." | ||
# => الحب لطوكيو كثيرا؛ هو مدهش أن نكون هنا. | ||
# Translated from Japanese to Italian | ||
$ export GT_LANGUAGE=Italian | ||
$ gt -t "私は東京がとても好きです。素晴らしいところです。" | ||
# => Mi piace molto Tokyo. È un posto meraviglioso. | ||
# Translated from Mandarin to Portuguese | ||
$ export GT_LANGUAGE=Portuguese | ||
$ gt -t "我深深地爱上了东京,来到这里真是太美妙了。" | ||
# => Eu me apaixonei profundamente por Tóquio, e estar aqui é realmente maravilhoso. | ||
``` | ||
|
||
## License | ||
|
||
This project is open-sourced under the MIT license. See [the License file](LICENSE) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
main() { | ||
BIN_DIR=${BIN_DIR-"$HOME/.bin"} | ||
mkdir -p $BIN_DIR | ||
|
||
case $SHELL in | ||
*/zsh) | ||
PROFILE=$HOME/.zshrc | ||
PREF_SHELL=zsh | ||
;; | ||
*/bash) | ||
PROFILE=$HOME/.bashrc | ||
PREF_SHELL=bash | ||
;; | ||
*/fish) | ||
PROFILE=$HOME/.config/fish/config.fish | ||
PREF_SHELL=fish | ||
;; | ||
*/ash) | ||
PROFILE=$HOME/.profile | ||
PREF_SHELL=ash | ||
;; | ||
*) | ||
echo "could not detect shell, manually add ${BIN_DIR} to your PATH." | ||
exit 1 | ||
esac | ||
|
||
if [[ ":$PATH:" != *":${BIN_DIR}:"* ]]; then | ||
echo >> $PROFILE && echo "export PATH=\"\$PATH:$BIN_DIR\"" >> $PROFILE | ||
fi | ||
|
||
PLATFORM="$(uname -s)" | ||
case $PLATFORM in | ||
Linux) | ||
PLATFORM="linux" | ||
;; | ||
Darwin) | ||
PLATFORM="darwin" | ||
;; | ||
*) | ||
err "unsupported platform: $PLATFORM" | ||
;; | ||
esac | ||
|
||
ARCHITECTURE="$(uname -m)" | ||
if [ "${ARCHITECTURE}" = "x86_64" ]; then | ||
# Redirect stderr to /dev/null to avoid printing errors if non Rosetta. | ||
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then | ||
ARCHITECTURE="aarch64" # Rosetta. | ||
else | ||
ARCHITECTURE="x86_64" # Intel. | ||
fi | ||
elif [ "${ARCHITECTURE}" = "arm64" ] ||[ "${ARCHITECTURE}" = "aarch64" ] ; then | ||
ARCHITECTURE="aarch64" # Arm. | ||
else | ||
ARCHITECTURE="x86_64" # Amd. | ||
fi | ||
|
||
BINARY_URL="https://github.com/fukumone/gt/releases/latest/download/gt-${PLATFORM}-${ARCHITECTURE}" | ||
echo $BINARY_URL | ||
|
||
echo "downloading latest binary" | ||
ensure curl -L "$BINARY_URL" -o "$BIN_DIR/gt" | ||
chmod +x "$BIN_DIR/gt" | ||
|
||
echo "installed - $("$BIN_DIR/gt" --version)" | ||
} | ||
|
||
# Run a command that should never fail. If the command fails execution | ||
# will immediately terminate with an error showing the failing | ||
# command. | ||
ensure() { | ||
if ! "$@"; then err "command failed: $*"; fi | ||
} | ||
|
||
main "$@" || exit 1 |
Oops, something went wrong.