Skip to content

ACPixel/try

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

try

A Go implementation of the Ruby try utility for quickly creating and navigating to temporary project folders.

Note: A child process cannot change the parent shell's directory, so shell integration is required. This is the same approach used by tools like zoxide, autojump, and z.

Features

  • Create dated folders: try some name creates ~/try/2025-10-09-some-name
  • Fuzzy search: Automatically finds and navigates to existing folders based on name (using sahilm/fuzzy)
  • Interactive selector: When multiple matches are found, shows an interactive menu with top 3 matches and "create new" option
  • Informative output: Displays folder name, creation date, and usage count when navigating
  • Tracks usage: SQLite database tracks folder creation dates, open count, and last opened time
  • Smart sorting: Results sorted by fuzzy match score, usage frequency, and last opened time
  • List/search folders: try list shows recent folders, and try list api filters with fuzzy search
  • Prune stale entries: Deleted folders are pruned automatically by default, and try prune can run cleanup manually
  • Configurable behavior: use the interactive try config editor, ~/.config/try/config, or environment variables to adjust storage and pruning

Installation

Install using Go:

go install github.com/ACPixel/try@latest

Or clone and build locally:

git clone https://github.com/ACPixel/try.git
cd try
go install

Setup Shell Integration

After installing, run:

try init

This will output shell integration code. Add it to your ~/.bashrc or ~/.zshrc:

try init >> ~/.bashrc
source ~/.bashrc

Or manually add:

try() {
    local output
    # Only capture stdout for cd command, let stderr through for interactive prompts
    output=$(command try "$@" 2>/dev/tty)
    if [ $? -eq 0 ]; then
        eval "$output"
    else
        return 1
    fi
}

Usage

After adding the alias, simply run:

# Create a new folder and cd into it
try my-project
# Creates: ~/try/2024-01-15-my-project and changes directory

# Later, fuzzy search will find it and cd into it
try my-proj
# Navigates to: ~/try/2024-01-15-my-project
# Output: ✓ my-project (2024-01-15, opened 2 times)

# If multiple matches are found, an interactive selector appears
try project
# Shows interactive menu with top 3 matches:
#   > project-a (2024-01-10, opened 5 times)
#     project-b (2024-01-12, opened 3 times)
#     project-c (2024-01-14, opened 1 times)
#     Create new: project

# List recent tries
try list

# Fuzzy-filter the list
try list proj

# Clean up database records for deleted folders
try prune

# Edit config interactively
try config

# Show active config and config file location
try config show

Configuration

By default, try stores folders and its SQLite database under ~/try. It also prunes database records for manually deleted folders on every use.

Run try config to edit settings interactively. You can also create ~/.config/try/config manually:

try_dir = "~/try"
prune_on_use = true

Environment variables override the config file, which is useful for one-off commands or scripts:

export TRY_DIR="$HOME/work/tries"
export TRY_PRUNE_ON_USE=false

How it works

  1. The Go binary searches the database for existing folders matching your query using fuzzy search
  2. If a single match is found, it displays folder info, updates usage stats, and outputs cd "path"
  3. If multiple matches are found, it shows an interactive selector with the top 3 matches and a "create new" option
  4. If no match is found, it creates a new dated folder with a normalized slug and outputs cd "path"
  5. The shell function wraps the binary and evals the output to change directory
  6. Folder information (name, date, usage count) is displayed in gray with a checkmark for easy identification
  7. The database schema is versioned with schema_migrations; databases without that table are treated as v0 and migrated automatically

Installing from Source

# Clone the repository
git clone https://github.com/ACPixel/try.git
cd try

# Install to $GOPATH/bin (or $HOME/go/bin if GOPATH is not set)
go install

# Or build locally
go build -o try main.go

Database

The SQLite database is stored at ~/try/try.db and tracks:

  • Folder paths
  • Names
  • Creation dates
  • Times opened
  • Last opened timestamp
  • Schema version

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages