Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Binary file added .coverage
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.venv
*.lastlogin
*__pycache__*
*.vscode*
Expand Down
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [Unreleased]

##### Added
- Centralized proxy management system for remote aliases
- New `xts proxy` command group with `add`, `list`, and `remove` subcommands
- Proxies are defined once and can be reused across multiple aliases
- Proxy configurations stored in separate `~/.xts/proxies.json` file
- **Multiple proxy types supported**: HTTP (default), HTTPS, SOCKS5, and SSH tunnels
- `--type` parameter to specify proxy protocol when adding a proxy
- Example: `xts proxy add sky proxy.company.com:8080 --type http --username user --password pass`
- SOCKS5 support for SSH tunnels and flexible routing
- Reference proxy when adding alias: `xts alias add allocator http://server:5000/allocator.xts --proxy sky`
- Enhanced test.sh script with optional test filters (--proxy, --remote, --alias, --all)
- Virtual environment support in test.sh for better dependency isolation
- Documentation for proxy feature in `docs/PROXY_FEATURE.md` and `examples/proxy_example.md`
- Comprehensive test suite for proxy functionality (5 tests in `test_xts_alias_remote.py::TestProxySupport`)

##### Changed
- **BREAKING**: Proxy configuration format changed from inline parameters to named references
- Old: `xts alias add <name> <url> --proxy <host:port> --proxy-username <user> --proxy-password <pass>`
- New: First define proxy: `xts proxy add <name> <host:port> --username <user> --password <pass>`
- Then reference it: `xts alias add <name> <url> --proxy <proxy_name>`
- Alias metadata now stores `proxy_name` reference instead of full proxy configuration
- Proxy credentials (including passwords) now stored in separate `~/.xts/proxies.json` file

##### Security
- Proxy credentials now stored in dedicated `~/.xts/proxies.json` file
- Allows for better security practices (e.g., separate gitignore, file permissions)
- Centralized credential management improves maintainability

#### [1.3.0](https://github.com/rdkcentral/xts_core/compare/1.2.1...1.3.0)

- Update #9 - Create build script to simplify and standardise building the xts app [`ac40bdc`](https://github.com/rdkcentral/xts_core/commit/ac40bdc4d1d2d6e3be7f87cb77e2687faa40e6eb)
Expand Down
252 changes: 252 additions & 0 deletions COMMAND_HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
# XTS Command History & Recall

## Quick Command Recall

### 1. **Arrow Keys** (Simplest)
- **↑ (Up Arrow)** - Recall previous command
- **↓ (Down Arrow)** - Move forward in history
- Press up arrow, then edit the command, then Enter

```bash
$ xts allocator list
{"slots":[]}
$ ↑ # Brings back: xts allocator list
# Edit to: xts allocator list_free
```

### 2. **Ctrl+R** (Reverse Search)
Search through your command history:
```bash
$ <Ctrl+R>
(reverse-i-search)`alloc': xts allocator alloc_by_id user@example.com 1 2h
```
- Type to search
- Ctrl+R again to cycle through matches
- Enter to execute
- Ctrl+C to cancel

### 3. **History Expansion**
Bash shortcuts for command reuse:

```bash
# Repeat last command
$ xts allocator list
$ !! # Runs: xts allocator list

# Repeat last command with sudo
$ !!

# Use last argument from previous command
$ xts allocator alloc_by_id user@example.com 5 2h
$ xts allocator release !$ # !$ = "2h" (last arg)
# Better: xts allocator release user@example.com 5

# Use specific argument
$ xts allocator alloc_by_id user@example.com 5 2h
$ xts allocator release !:2 !:3 # !:2 = user@example.com, !:3 = 5

# Repeat last command starting with "xts"
$ !xts

# Repeat last command containing "allocator"
$ !?allocator
```

### 4. **Edit Last Command**
Quickly fix typos:
```bash
$ xts allocator alloc_by_id usr@example.com 5 2h # Typo: "usr"
$ ^usr^user # Replaces usr with user and runs
# Executes: xts allocator alloc_by_id user@example.com 5 2h
```

### 5. **History Command**
View and reuse from history:
```bash
# Show recent commands
$ history 20

# Execute command by number
$ !542 # Runs command #542 from history

# Show only xts commands
$ history | grep xts
```

## Enhanced Bash Configuration

Add these to your `~/.bashrc` for better history:

```bash
# Increase history size
export HISTSIZE=10000
export HISTFILESIZE=20000

# Don't store duplicate commands
export HISTCONTROL=ignoredups:erasedups

# Append to history (don't overwrite)
shopt -s histappend

# Save multi-line commands as one entry
shopt -s cmdhist

# Real-time history sharing across sessions
PROMPT_COMMAND="history -a; history -n"

# Enable Ctrl+S for forward search (reverse of Ctrl+R)
stty -ixon
```

After adding these, reload:
```bash
source ~/.bashrc
```

## XTS-Specific Aliases

Create bash aliases for common xts commands:

```bash
# Add to ~/.bashrc
alias xa='xts allocator'
alias xal='xts allocator list'
alias xalf='xts allocator list_free'
alias xaa='xts allocator alloc_by_id'
alias xar='xts allocator release'

# Now you can use:
$ xal # Instead of: xts allocator list
$ xaa user@example.com 5 2h # Allocate device 5
```

## Readline (inputrc) Enhancements

Add to `~/.inputrc` for better tab completion behavior:

```bash
# Create/edit ~/.inputrc
$ nano ~/.inputrc
```

Add these lines:
```
# Show all completions immediately
set show-all-if-ambiguous on

# Case-insensitive completion
set completion-ignore-case on

# Colored completion
set colored-stats on
set colored-completion-prefix on

# Menu completion - cycle through options with tab
"\t": menu-complete
"\e[Z": menu-complete-backward

# Show completion type indicators
set visible-stats on

# Immediately show completion matches
set show-all-if-unmodified on
```

Reload:
```bash
$ bind -f ~/.inputrc
```

## Practical Workflow Examples

### Example 1: Allocate, Test, Release
```bash
# Step 1: Allocate
$ xts allocator alloc_by_id user@example.com 5 2h
{"status":"success","device_id":5}

# Step 2: Use it (remember the command)
$ ↑ # Recall allocation command
# Edit to release: xts allocator release user@example.com 5
```

### Example 2: List, Then Allocate Specific Device
```bash
# See available devices
$ xts allocator list_free

# Pick one, reuse the alias name with tab completion
$ xts allocator alloc_<TAB> # Completes to alloc_by_id, alloc_by_platform, etc.
```

### Example 3: Repeat with Modifications
```bash
# Allocate device 5
$ xts allocator alloc_by_id user@example.com 5 2h

# Release it
$ ↑ # Recall
# Change "alloc_by_id" to "release" and remove "2h"
$ xts allocator release user@example.com 5
```

## Advanced: fzf Integration (Optional)

For even better history search, install [fzf](https://github.com/junegunn/fzf):

```bash
# Install
$ sudo apt install fzf # or: git clone https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install

# Add to ~/.bashrc
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
```

Now:
- **Ctrl+R** - Interactive fuzzy history search with preview
- **Ctrl+T** - Fuzzy file finder
- **Alt+C** - Fuzzy directory changer

## Tips & Tricks

1. **Quick Edit**: Start typing a command, then ↑ to search history for commands starting with those characters

2. **Job Control**:
```bash
$ xts allocator list # Takes a while...
<Ctrl+Z> # Suspend
$ bg # Continue in background
$ fg # Bring back to foreground
```

3. **Command Substitution**:
```bash
# Use output of one command in another
$ DEVICE=$(xts allocator list | jq -r '.slots[0].id')
$ xts allocator alloc_by_id user@example.com $DEVICE 2h
```

4. **For Loops for Batch Operations**:
```bash
# Release multiple devices
$ for id in 1 2 3; do xts allocator release user@example.com $id; done
```

## Summary

**Fastest methods for command recall:**

| Action | Method | Example |
|--------|--------|---------|
| Recall last command | `↑` | Press up arrow |
| Search history | `Ctrl+R` | Ctrl+R, type "alloc" |
| Repeat last command | `!!` | `!!` |
| Fix typo | `^old^new` | `^usr^user` |
| Use last argument | `!$` | `command !$` |

**After running a command, you can:**
1. Press `↑` to recall it
2. Press `Ctrl+R` and search for it
3. Type the start of the command and press `↑` to search matching history

Unfortunately, **tab completion cannot recall history** - that's a shell limitation. But the methods above are faster than tab-tab anyway!
Loading