أدوات CLI
2 دقيقة للقراءة

GitHub Copilot: الإعدادات

مقدمة

هذا الدليل الشامل يغطي جميع خيارات الإعداد والتكوين لـ GitHub Copilot CLI، من التثبيت الأساسي إلى التخصيص المتقدم.


التثبيت والإعداد الأولي

1. التثبيت

# تأكد من GitHub CLI
gh --version
# GitHub CLI version 2.40.0+ required

# تسجيل الدخول
gh auth login
# Follow the prompts

# تثبيت الامتداد
gh extension install github/gh-copilot

# التحقق من التثبيت
gh copilot --version
# gh-copilot version x.x.x

2. التحقق من الاتصال

# اختبار الاتصال
gh copilot suggest "test"

# إذا نجح، ستحصل على اقتراح
# إذا فشل، تحقق من:
# - GitHub account status
# - Copilot subscription
# - Internet connection

Aliases (الاختصارات)

Bash/Zsh Aliases

# إضافة إلى ~/.bashrc أو ~/.zshrc

# Aliases الأساسية
alias cs='gh copilot suggest'
alias ce='gh copilot explain'

# Aliases متقدمة
alias csi='gh copilot suggest --interactive'
alias csd='gh copilot suggest --detailed'
alias cex='gh copilot explain --detailed'

# بعد التعديل:
source ~/.bashrc  # أو source ~/.zshrc

# الاستخدام
cs "list all files"
ce "ls -la | grep .txt"

PowerShell Aliases

# إضافة إلى $PROFILE (Microsoft.PowerShell_profile.ps1)

# Functions لل_aliases
function cs {
    gh copilot suggest $args
}

function ce {
    gh copilot explain $args
}

function csi {
    gh copilot suggest --interactive $args
}

function ced {
    gh copilot explain --detailed $args
}

# بعد التعديل:
. $PROFILE

# الاستخدام
cs "get process by name"
ce "Get-Process | Sort-Object CPU"

Fish Shell Aliases

# إضافة to ~/.config/fish/config.fish

# Abbreviations (أفضل من aliases في fish)
abbr cs 'gh copilot suggest'
abbr ce 'gh copilot explain'
abbr csi 'gh copilot suggest --interactive'
abbr ced 'gh copilot explain --detailed'

# الاستخدام
cs "list files"
ce "docker ps"

Shell Configuration Files

Configuration Options

# ~/.config/gh/gh-copilot-config.yml (محتمل في المستقبل)

# حالياً، التكوين عبر:
# 1. Environment variables
# 2. Aliases
# 3. Shell functions

Environment Variables

Available Variables

# GitHub Token
export GH_TOKEN="ghp_xxxxxxxxxxxx"

# Copilot-specific (if available)
export COPILOT_MODEL="gpt-4"
export COPILOT_MAX_SUGGESTIONS="3"

# Language preference
export LANG="ar_SA.UTF-8"  # للغة العربية

Setting Variables Permanently

# في ~/.bashrc أو ~/.zshrc

# GitHub Token
export GH_TOKEN="ghp_xxxxxxxxxxxx"

# Copilot preferences
export COPILOT_MODEL="gpt-4"
export COPILOT_MAX_SUGGESTIONS="3"

# Reload shell
source ~/.bashrc

التخصيص المتقدم

Custom Shell Functions

# في ~/.bashrc أو ~/.zshrc

# Function للاقتراحات مع التنفيذ التلقائي
cs-run() {
    local suggestion
    suggestion=$(gh copilot suggest "$*" | head -1)
    echo "Running: $suggestion"
    eval "$suggestion"
}

# Function لشرح وتنفيذ
ce-run() {
    local explanation
    local command
    explanation=$(gh copilot explain "$*")
    echo "$explanation"
    echo "Run this command? (y/n)"
    read -r answer
    if [ "$answer" = "y" ]; then
        eval "$*"
    fi
}

# Function للاقتراحات المتعددة
cs-multi() {
    gh copilot suggest "$*" --suggestions 3
}

# الاستخدام
cs-run "list all python files"
ce-run "docker ps -a"
cs-multi "compress folder"

Interactive Prompts

# Function لاختيار تفاعلي
cs-interactive() {
    local prompt="$*"
    local suggestions

    suggestions=$(gh copilot suggest "$prompt" --suggestions 3)

    echo "Suggestions for: $prompt"
    echo "$suggestions" | nl -w2 -s'. '

    echo "Choose (1-3):"
    read -r choice

    local selected
    selected=$(echo "$suggestions" | sed "${choice}q;d")

    echo "Selected: $selected"
    echo "Run? (y/n)"
    read -r confirm

    if [ "$confirm" = "y" ]; then
        eval "$selected"
    fi
}

# الاستخدام
cs-interactive "kill process on port 3000"

التكامل مع الأدوات الأخرى

Git Aliases

# في ~/.gitconfig

[alias]
    # Copilot-powered git aliases
    suggest = "!f() { gh copilot suggest "$*"; }; f"
    explain = "!f() { gh copilot explain "$*"; }; f"

    # أمثلة محددة
    undo = "!f() { gh copilot suggest "undo last commit but keep changes" | head -1 | sh; }; f"
    cleanup = "!f() { gh copilot suggest "delete merged branches" | head -1 | sh; }; f"

# الاستخدام
git suggest "commit all changes"
git explain "rebase -i HEAD~3"
git undo
git cleanup

Docker Integration

# Function للـ Docker helper
docker-help() {
    if [ -z "$1" ]; then
        echo "Usage: docker-help <description>"
        return 1
    fi

    gh copilot suggest "docker $*"
}

# Examples
docker-help "stop all containers"
docker-help "remove unused images"
docker-help "show container logs"

Kubernetes Integration

# Function للـ K8s helper
k8s-help() {
    if [ -z "$1" ]; then
        echo "Usage: k8s-help <description>"
        return 1
    fi

    gh copilot suggest "kubectl $*"
}

# Examples
k8s-help "get all pods in all namespaces"
k8s-help "restart deployment"
k8s-help "describe pod failure"

Performance Tuning

Cache Settings

# Copilot CLI يستخدم cache لل suggestions

# مسح الcache (if needed)
gh cache delete

# تعطيل الcache (not recommended)
export GH_COPILOT_CACHE_DISABLE=true

Connection Settings

# Timeout settings
export GH_COPILOT_TIMEOUT=30  # seconds

# Retry settings
export GH_COPILOT_MAX_RETRIES=3

# Proxy settings (if needed)
export HTTP_PROXY="http://proxy.example.com:8080"
export HTTPS_PROXY="http://proxy.example.com:8080"

Language & Localization

Arabic Support

# تأكد من إعدادات اللغة
locale  # check current locale

# تعيين اللغة العربية
export LANG="ar_SA.UTF-8"
export LANGUAGE="ar:en"

# استخدام بالعربية
gh copilot suggest "احذف الملفات الكبيرة"
gh copilot explain "الأمر السابق"

Multi-language Input

# Copilot CLI يدعم:
- English 🇬🇧
- Arabic 🇸🇦
- Spanish 🇪🇸
- French 🇫🇷
- German 🇩🇪
- Chinese 🇨🇳
- Japanese 🇯🇵
- And more...

# أمثلة
gh copilot suggest "list files"      # English
gh copilot suggest "listar archivos" # Spanish
gh copilot suggest "lister fichiers" # French

Security Configuration

Data Privacy

# Copilot CLI لا يرسل:
- Passwords
- API keys
- Sensitive data (detected automatically)

# لكن يمكنك التحكم:
export COPILOT_TELEMETRY="false"     # تعطيل telemetry
export COPILOT_DATA_SHARING="false"  # تعطيل مشاركة البيانات

Private Mode

# Function لprivate mode
cs-private() {
    local prompt="$*"

    echo "⚠️  Private Mode: No data will be shared"
    echo "Prompt: $prompt"
    echo "Continue? (y/n)"
    read -r confirm

    if [ "$confirm" = "y" ]; then
        COPILOT_DATA_SHARING="false" gh copilot suggest "$prompt"
    fi
}

# الاستخدام
cs-private "process user data"

Troubleshooting Configuration

Check Installation

# Script للتحقق من التكوين
check-copilot-config() {
    echo "Checking Copilot CLI configuration..."

    # GitHub CLI version
    echo "GitHub CLI: $(gh --version)"

    # Copilot version
    echo "Copilot: $(gh copilot --version)"

    # Auth status
    echo "Auth status: $(gh auth status)"

    # Aliases
    echo "Aliases:"
    type cs 2>/dev/null && echo "  ✅ cs alias set" || echo "  ❌ cs alias not set"
    type ce 2>/dev/null && echo "  ✅ ce alias set" || echo "  ❌ ce alias not set"

    # Environment variables
    echo "Environment:"
    echo "  GH_TOKEN: ${GH_TOKEN:+✅ set}"
    echo "  LANG: $LANG"

    # Test connection
    echo "Testing connection..."
    gh copilot suggest "test" >/dev/null 2>&1 && echo "  ✅ Connection OK" || echo "  ❌ Connection failed"
}

# الاستخدام
check-copilot-config

Reset Configuration

# إعادة تعيين التكوين

# 1. إزالة الامتداد
gh extension remove github/gh-copilot

# 2. إعادة التثبيت
gh extension install github/gh-copilot

# 3. إعادة المصادقة
gh auth login

# 4. التحقق
gh copilot --version

Best Practices

DO's ✅

  1. استخدم aliases مخصصة

    # اختصارات مختصرة وواضحة
    alias cs='gh copilot suggest'
    alias ce='gh copilot explain'
    
  2. وظف shell functions

    # functions للعمليات المعقدة
    cs-run() { ... }
    
  3. ضبط language settings

    # للغة العربية
    export LANG="ar_SA.UTF-8"
    
  4. استخدم environment variables

    # للتكوين المستمر
    export GH_TOKEN="..."
    

DON'Ts ❌

  1. لا تشارك tokens

    # سيء
    echo "My token: $GH_TOKEN"
    
    # جيد
    # استخدم ~/.ghconfig.yml أو env file
    
  2. لا تستخدم aliases غامضة

    # سيء
    alias x='gh copilot suggest'
    
    # جيد
    alias cs='gh copilot suggest'
    
  3. لا تعطل cache

    # سيء
    export GH_COPILOT_CACHE_DISABLE=true
    
    # جيد
    # دع Copilot يدير cache
    

Complete Configuration Example

Full ~/.bashrc Example

# ~/.bashrc

# GitHub Copilot CLI Configuration

# Aliases
alias cs='gh copilot suggest'
alias ce='gh copilot explain'
alias csi='gh copilot suggest --interactive'
alias ced='gh copilot explain --detailed'

# Environment Variables
export GH_TOKEN="ghp_xxxxxxxxxxxx"
export LANG="ar_SA.UTF-8"

# Shell Functions
cs-run() {
    local suggestion
    suggestion=$(gh copilot suggest "$*" | head -1)
    echo "Running: $suggestion"
    eval "$suggestion"
}

cs-interactive() {
    local prompt="$*"
    local suggestions

    suggestions=$(gh copilot suggest "$prompt" --suggestions 3)

    echo "Suggestions for: $prompt"
    echo "$suggestions" | nl -w2 -s'. '

    echo "Choose (1-3):"
    read -r choice

    local selected
    selected=$(echo "$suggestions" | sed "${choice}q;d")

    echo "Selected: $selected"
    echo "Run? (y/n)"
    read -r confirm

    if [ "$confirm" = "y" ]; then
        eval "$selected"
    fi
}

docker-help() {
    gh copilot suggest "docker $*"
}

k8s-help() {
    gh copilot suggest "kubectl $*"
}

# Completion
if command -v gh &>/dev/null; then
    eval "$(gh completion -s bash)"
fi

الخلاصة

Copilot CLI Configuration يشمل:

  1. Basic Setup:

    • ✅ Installation
    • ✅ Authentication
    • ✅ Verification
  2. Aliases:

    • ✅ Bash/Zsh
    • ✅ PowerShell
    • ✅ Fish
  3. Customization:

    • ✅ Shell functions
    • ✅ Environment variables
    • ✅ Integration with other tools
  4. Optimization:

    • ✅ Performance tuning
    • ✅ Cache settings
    • ✅ Security settings
  5. Localization:

    • ✅ Arabic support
    • ✅ Multi-language input

ابدأ بتكوين Copilot CLI:

# 1. أضف aliases المفضلة لديك
# 2. وظف shell functions
# 3. خصّص حسب احتياجاتك
# 4. استمتع بالإنتاجية!

موارد إضافية