DEV Community

Flavio Espinoza
Flavio Espinoza

Posted on • Edited on

Supercharge Your Coding with AI-Enhanced Shell Aliases

AI-enhanced terminal aliases for developers — streamline workflows with custom Zsh shortcuts like pfiles, ptree, and ChatGPT-assisted commands in a futuristic coding environment.

To streamline project analysis and improve collaboration with ChatGPT, I created a set of aliases: pfiles, pfilescd, ptree, ptreecd, pg, and pgcd. These aliases generate .txt files that provide a comprehensive overview of a project's structure and codebase. These files can be uploaded to ChatGPT for help with coding, debugging, and refactoring.


Aliases Overview

1. pfiles

  • Purpose: Concatenates all .ts, .tsx, .json, and .md files in the src directory into a single file.
  • Output File: <project-name>-files-YYYY-MM-DD.txt
  • Usage:
  pfiles
Enter fullscreen mode Exit fullscreen mode

2. pfilescd

  • Purpose: Concatenates all text-based files in the current directory (excluding common build/system folders and .txt files), prefixing each section with the filename.
  • Output File: <project-name>-files-YYYY-MM-DD__<current-directory>.txt
  • Usage:
  pfilescd
Enter fullscreen mode Exit fullscreen mode

3. ptree

  • Purpose: Creates a tree view of the src directory, excluding ignored folders and files.
  • Output File: <project-name>-structure-YYYY-MM-DD.txt
  • Usage:
  ptree
Enter fullscreen mode Exit fullscreen mode

4. ptreecd

  • Purpose: Creates a tree view of the current directory with filtering.
  • Output File: <project-name>-structure-YYYY-MM-DD__<current-directory>.txt
  • Usage:
  ptreecd
Enter fullscreen mode Exit fullscreen mode

5. pg The g stands for GO!

  • Purpose: Runs pfiles and then ptree in sequence.
  • Usage:
  pg
Enter fullscreen mode Exit fullscreen mode

6. pgcd

  • Purpose: Runs pfilescd and then ptreecd in sequence.
  • Usage:
  pgcd
Enter fullscreen mode Exit fullscreen mode

Setting Up Custom Aliases in .zshrc and .bash_profile

This section shows how to create a reusable alias file (~/.zshrc_my_aliases), import it into your main shell config (.zshrc or .bash_profile), and make sure it's sourced properly.


Step 1: Create the Alias File

Open the alias file using VS Code:

code ~/.zshrc_my_aliases
Enter fullscreen mode Exit fullscreen mode

Paste the following content into it:

# pfiles alias: Finds and concatenates files in the 'src' directory (with extensions .ts, .tsx, .json, .md) into a file named <project-name>-files-YYYY-MM-DD.txt.
alias pfiles="find src -type f \\( -name '*.ts' -o -name '*.tsx' -o -name '*.json' -o -name '*.md' \\) -exec echo '===== {} =====' \\; -exec cat {} \\; > $(basename $(pwd))-files-$(date +%Y-%m-%d).txt 2>/dev/null && echo '✅ $(basename $(pwd))-files-$(date +%Y-%m-%d).txt created.'"

# pfilescd alias: Finds and concatenates all text-based files in the current directory (excluding 'node_modules', '.git', '.next', '/temp', and '.txt' files) into a file named <project-name>-files-YYYY-MM-DD__<current-directory>.txt. Each file's content is prefixed with its path for clarity.
alias pfilescd='project_name=$(basename "$(git rev-parse --show-toplevel 2>/dev/null || pwd)") && current_dir=$(basename "$PWD") && date_str=$(date +%F) && filename="${project_name}-files-${date_str}__${current_dir}.txt" && find . -type f \( -name "*.js" -o -name "*.ts" -o -name "*.tsx" -o -name "*.json" -o -name "*.md" -o -name "*.html" -o -name "*.css" \) ! -path "*/node_modules/*" ! -path "*/.git/*" ! -path "*/.next/*" ! -path "*/temp/*" ! -name "*.txt" -exec sh -c '"'"'for file; do echo "===== $file ====="; cat "$file"; echo; done'"'"' sh {} + > "$filename" && echo "Saved to $filename"'

# ptree alias: Generates a directory tree structure for the 'src' directory only, excluding 'node_modules', '.git', 'dist', '.next', and '.txt' files. Saves the output to a file named <project-name>-structure-YYYY-MM-DD.txt.
alias ptree="tree src -I 'node_modules|.git|dist|.next|*.txt' -L 10 > $(basename $(pwd))-structure-$(date +%Y-%m-%d).txt 2>/dev/null && echo '✅ $(basename $(pwd))-structure-$(date +%Y-%m-%d).txt created.'"

# ptreecd alias: Generates a directory tree structure for the current directory (excluding 'node_modules', '.git', 'dist', '.next', '/temp', and '.txt' files) and saves it to a file named <project-name>-structure-YYYY-MM-DD__<current-directory>.txt.
alias ptreecd='project_name=$(basename "$(git rev-parse --show-toplevel 2>/dev/null || pwd)") && current_dir=$(basename "$PWD") && date_str=$(date +%F) && filename="${project_name}-structure-${date_str}__${current_dir}.txt" && tree -I "node_modules|.git|dist|.next|temp|*.txt" > "$filename" && echo "Saved to $filename"'

# pg alias: Runs pfiles first to create a file list, then runs ptree to generate a directory tree structure.
alias pg="pfiles && ptree"

# pgcd alias: Runs pfilescd followed by ptreecd to generate both the concatenated file contents and the directory structure of the current project.
alias pgcd='pfilescd && ptreecd'
Enter fullscreen mode Exit fullscreen mode

Step 2: Import into .zshrc

Edit your .zshrc file:

code ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Add the following line at the end:

source ~/.zshrc_my_aliases
Enter fullscreen mode Exit fullscreen mode

Then reload your terminal config:

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Step 3: Bash Users – Import into .bash_profile

If you're using Bash:

code ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Add this line:

source ~/.zshrc_my_aliases
Enter fullscreen mode Exit fullscreen mode

Then reload:

source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Example Output Files

Assume your project is called ai-chat-assistant.

1. ai-chat-assistant-files-2025-03-23.txt

Contains the contents of all matching files in src.

Example:

// ===== src/app/layout.tsx =====
import type { Metadata } from 'next'
import { Geist, Geist_Mono } from 'next/font/google'
import './globals.css'

...

// ===== src/app/page.tsx =====
import React from 'react'

export default function Page() {
    return (
        <div>
            <h1 className="text-lg font-bold">App Page</h1>
            <p>This is the app page content.</p>
        </div>
    )
}

...
Enter fullscreen mode Exit fullscreen mode

2. ai-chat-assistant-structure-2025-03-23.txt

Contains the tree structure of the src folder.

Example:

src
├── app
│   ├── layout.tsx
│   └── page.tsx
└── components
    └── ui
        ├── button.tsx
        └── card.tsx
Enter fullscreen mode Exit fullscreen mode

How to Use with ChatGPT

  1. Generate the .txt files using pg or pgcd.
  2. Upload them in the ChatGPT chat window.
  3. Use a prompt like:
I'm working on a Next.js TypeScript project called `ai-chat-assistant`.

1. `ai-chat-assistant-files-2025-03-23.txt`: all code content.
2. `ai-chat-assistant-structure-2025-03-23.txt`: directory layout.

Can you help debug `src/app/api/chat/route.ts`?
Enter fullscreen mode Exit fullscreen mode

Benefits

  • Quickly packages relevant project files for review.
  • Gives ChatGPT proper context.
  • Works across directories and project structures.
  • Easy to reuse and extend.

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

DEV shines when you're signed in, unlocking a customized experience with features like dark mode!

Okay