Tuesday, February 20, 2024

Run tree command respecting .gitignore

#!/bin/bash
# /opt/scripts/tree-gitignore.sh
# Author: Nestor Urquiza
# Date: 20240220
# Description: A tree wrapper to show contents of a git project respecting .gitignore
# Usage: cd git-project && /opt/scripts/tree-gitignore.sh
cmd="tree -a -I '.git'"
# Read each line from .gitignore
while IFS= read -r line; do
# Skip empty lines and comments
if [[ "$line" != "" && "$line" != \#* ]]; then
# Remove leading "**/" from patterns, if present
pattern="${line/\*\*\//}"
# Remove trailing "/*" from patterns, if present
pattern="${pattern/\/\*/}"
# Append each cleaned pattern as an ignore option
cmd+=" -I '$pattern'"
fi
done < .gitignore
# Execute the constructed command
eval $cmd

Monday, February 19, 2024

My .vimrc for google (and amazon) cloud shell

Will keep here what I am using in google (and amazon) cloud shells.
" keep all defaults
source $VIMRUNTIME/defaults.vim
" disable visual mode when using mouse
set mouse=c
" keep all defaults
source $VIMRUNTIME/defaults.vim
" disable visual mode when using mouse
set mouse=c
" paste as copied
set paste
" indentation
set tabstop=2        " Set the width of a tab character to 2 spaces
set shiftwidth=2     " Set the number of spaces to use for each step of (auto)indent
set expandtab        " Convert tabs to spaces
set softtabstop=2    " Set the number of spaces a Tab counts for while performing editing operations, like inserting a Tab or using BS
set smartindent      " Enable smart indenting for new lines

Sharing code without using git

Sometimes you do not want to commit to git for security reasons and yet you want to test your code somewhere else.
Run the below from your local copy of the git repository:
rsync -av --exclude-from='.gitignore' --exclude='.git' . ~/Downloads/my-repo-copy
cd ~/Downloads/my-repo-copy
zip -r ~/Downloads/my-repo-copy.zip ./
Copy the content to the remote location and run the below:
mkdir my-repo
mv my-repo-copy.zip my-repo/
cd my-repo
unzip my-repo-copy.zip
rm my-repo-copy.zip

Followers