Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ doc
play
dist/
.vscode
cli
215 changes: 77 additions & 138 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,174 +8,113 @@

- [Usage](#usage)
- [Installation](#installation)
- [Linux](#linux)
- [Windows](#windows)
- [Mac](#mac)
- [Authentication](#authentication)
- [Authentication & Setup](#authentication--setup)
- [Config File](#configuration)
- [Docs](#docs)

## Usage


### Main Usage

- post tweets from terminal like this

### Quick Start
Post a tweet directly from your terminal:
```bash
x "first tweet from terminal!"
```

### Full Docs
### Commands Overview

```bash

interact with x (twitter) from terminal.

USAGE
x <command>

Main usage (posting a tweet)
x <tweet-text>
Examples:
one word tweet (no spaces) x hi
multiple words tweet x "hi from terminal"
with optional arg: x -t "hi there"
extended optional arg: x --tweet "hi x"

Commands
-h show this help
auth start authorizing your X account
auth --url get auth url if it didn't open browser after running 'x auth'
auth -v verify authorization after running 'x auth'
-t "text" post a tweet
-v show version
-c clear authorized account
COMMANDS
init Manage your Twitter Developer Apps (Add, Use, Delete)
auth Authenticate the active app with your Twitter account
tweet (t) Post a tweet
version (v) Show CLI version
```

## Installation

### Linux

- download the verion that matches computer's operating system from [latest release](https://github.com/devhindo/x/releases/latest)
- open a terminal in the directory where the file was downloaded
- for example assume the file name is `x_Linux_x86_64.tar.gz`
- remove any previous downloaded version of x
### Linux / macOS
1. Download the latest release binary.
2. Move it to your path:
```bash
chmod +x x
sudo mv x /usr/local/bin/
```

### Windows
1. Download the `x.exe` binary.
2. Add its location to your System PATH.

## Authentication & Setup

The CLI is now **local-first**. You need to bring your own Twitter Developer App credentials.

### 1. Create a Twitter App & Get Credentials
**Important:** Do NOT use the "Consumer Keys" or "Bearer Token". You need the **OAuth 2.0 Client ID and Secret**.

1. Go to the [Twitter Developer Portal](https://developer.twitter.com/en/portal/dashboard) and create a Free project/app.
2. Navigate to your App's **Settings**.
3. Under **User authentication settings**, click **Edit** (or Set up).
4. Configure the following:
- **App Permissions**: Select "Read and write".
- **Type of App**: Select "Native App".
- **Redirect URL**: Enter `http://localhost:3000/callback`. **This is critical.**
- **Website URL**: Enter any valid URL (e.g., `https://twitter.com`).
5. Click **Save**.
6. **IMMEDIATELY COPY** the **Client ID** and **Client Secret** shown on the screen.
- *Note: These are different from the API Key and Secret found in the "Keys and Tokens" tab.*

### 2. Register App in CLI
Run the interactive init wizard:
```bash
sudo rm -rf /usr/local/x
x init add
```
Follow the prompts to enter your App Name, Client ID, and Client Secret.

- run the following command to extract the file

### 3. Authenticate
Once added, authenticate your user account:
```bash
sudo tar -C /usr/local -xzf x_Linux_x86_64.tar.gz
x auth
```
This will open your browser to authorize the app.

- Add `/usr/local/x` to the PATH environment variable
- Do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):

### 4. Manage Multiple Apps
You can add multiple apps and switch between them:
```bash
# opening the file
nano $HOME/.profile

# and add this line at the end of the file
export PATH=$PATH:/usr/local/x
x init use # Switch active app
x init delete # Delete an app
```

- run the following command to update the current session

```bash
source $HOME/.profile
## Configuration

Your data is stored locally in `~/.x-cli/config.json`.

### Config Structure
```json
{
"active_app": "MyBot",
"apps": [
{
"name": "MyBot",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"user": {
"access_token": "EncryptedOAuthToken...",
"refresh_token": "EncryptedRefreshToken...",
"expiry": "2024-05-20T15:04:05Z"
}
}
]
}
```

- verify the installation by running the following command

```bash
x version
```

- if the installation was successful, you should see the version of x that was installed

### Windows

- download the verion that matches your archeticture from [latest release](https://github.com/devhindo/x/releases/latest)
- extract the file and get the `x.exe` file and place it in a directory that is in your PATH environment variable. a common one is `C:\Windows\system32`
- open a terminal and run `x --version` to verify the installation
- if the installation was successful, you should see the version of x that was installed

### Mac

- idk never used it before. but I have darwin binaries in the [latest release](https://github.com/devhindo/x/releases/latest) so you can try it out

## Authentication

- run `x auth`
- an auth url will be opened in your browser, if it doesn't run `x auth --url` to get the url
- verify `X CLI` in the opened twitter page
- after authorizing the app return to the terminal and run `x auth -v`
- **active_app**: The name of the app currently being used for tweets.
- **apps**: List of all registered apps.
- **user**: Contains the OAuth tokens for the authenticated user. This is automatically populated/updated when you run `x auth` or when the CLI refreshes your token.

Note: running `x auth -v` windows might flag the tool as a threat this is because it reads a config file that was previously generated [here](https://github.com/devhindo/x/blob/b00b1a911e1e7ac364dd2d10f941e95d76bfb3ac/src/cli/lock/key.go#L13) to identify the user by a random string that's unique for your device. you can check the function [here](https://github.com/devhindo/x/blob/b00b1a911e1e7ac364dd2d10f941e95d76bfb3ac/src/cli/lock/key.go#L42C1-L42C1). so if the threat shows up, allow it and continue.

- if the authorization was successful, you should see a `verified` message
- now you can post tweets using `x -t "tweet text"`
- if anything went wrong run `x -c` to clear any settings and start over
- if the problem persists, kindly open an issue [here](https://github.com/devhindo/x/issues/new) and describe the problem and I'll be happy to help!


## Posting tweets

`x -t "tweet text"` or `x --tweet "tweet text"` or `x "hi there!"` or even one word tweet like `x spotifyURL`
**Security Note:** This file contains sensitive credentials. Ensure your home directory is secure.

## Docs
[Docs](https://deepwiki.com/devhindo/x)

## Detailed Documentation

The CLI has been updated to use a more robust command structure.

### Global Options
- `-h, --help`: Help for any command

### Commands

#### `x [message]`
Post a tweet directly.
```bash
x "Hello World"
```

#### `tweet` (alias: `t`)
Post a tweet.
```bash
x tweet "Hello World"
x t "Hello World"
```

#### `auth`
Manage authentication.
- `x auth`: Start authentication flow
- `x auth --verify` (or `-v`): Verify authentication status
- `x auth --clear` (or `-c`): Clear stored credentials
- `x auth --url`: Display the authorization URL

#### `future` (alias: `f`)
Schedule a tweet for later.
```bash
x future "Tweet later" 2h30m
x f "Tweet later" 5h
```
Arguments:
1. Message: The tweet content
2. Duration: Time to wait (e.g., "1h", "30m", "1h30m")

#### `version` (alias: `v`)
Print the CLI version.
```bash
x version
```

### Legacy Support
The following legacy flag styles are still supported for backward compatibility:
- `x -t "msg"` -> `x t "msg"`
- `x -f "msg" "time"` -> `x f "msg" "time"`
- `x -v` -> `x version`
44 changes: 29 additions & 15 deletions src/cli/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,40 @@ import (
"fmt"
"os"

"github.com/devhindo/x/src/cli/lock"
"github.com/devhindo/x/src/cli/config"
)

// func check_authentication() {}

func Auth() {
cfg, err := config.LoadConfig()
if err != nil {
fmt.Println("Error loading config:", err)
os.Exit(1)
}

checkIfUserExists()
if len(cfg.Apps) == 0 {
fmt.Println("No apps found. Run 'x init add' first.")
os.Exit(1)
}

u := newUser()
u.add_user_to_db()
u.open_browser_to_auth_url()
fmt.Println("please authorize X CLI in your browser then run 'x auth --verify'")
fmt.Println("if the browser does not open, run 'x auth --url` to get the authorization url")
}
app := cfg.GetActiveApp()
if app == nil {
// Fallback to first app if active not set
if len(cfg.Apps) > 0 {
app = &cfg.Apps[0]
cfg.ActiveApp = app.Name
config.SaveConfig(cfg)
} else {
fmt.Println("No apps found. Run 'x init add' first.")
os.Exit(1)
}
}

func checkIfUserExists() {
_, err := lock.ReadLicenseKeyFromFile()
if err == nil {
fmt.Println("a user is already logged in | try 'x -h'")
os.Exit(0)
fmt.Printf("Authenticating app '%s'...\n", app.Name)
err = StartAuthFlow(app)
if err != nil {
fmt.Println("Authentication failed:", err)
os.Exit(1)
}

fmt.Println("Authentication successful! You can now use 'x tweet'.")
}
59 changes: 0 additions & 59 deletions src/cli/auth/crud.go

This file was deleted.

21 changes: 0 additions & 21 deletions src/cli/auth/geturl.go

This file was deleted.

Loading
Loading