πŸ¦ͺ 5 Shell Tricks, because why not

This is a short 🩳; a note that doesn’t merit a full post. See all shorts here.

No time, let’s just go. This is zsh on MacOS.

Copy current dir name

Useful for when you copy a pyproject from another directory and want to rename the project to the current directory

basename $(pwd) | pbcopy

Pomodoro πŸ…

added two new functions to my .zshrc file: work and rest, which give me a built-in #pomodoro in the terminal. From Simple CLI Pomodoro timer for macOS by Patrick Loeber. This also taught me a nice library which might be useful for work: terminal-notifier.

Grab the latest downloaded thing

Added a new function to grab the latest downloaded file to the current directory with some pretty printing:

grab_download() {
    # Define variables
    latest_file=$(ls -dtr1 ~/Downloads/* | tail -1)
    current_dir=$(pwd)

    # Check if gum is installed
    if ! command -v gum &> /dev/null
    then
        echo "gum is not installed. Please install gum from https://github.com/charmbracelet/gum"
        return 1
    fi

    # Display information about the latest file
    file_info=$(file "$latest_file")
    gum style --bold --foreground "#FFA500" --border normal --border-foreground "#00FF00" "πŸ“„ Latest Downloaded File:" && gum style --italic --foreground "#00FFFF" "$file_info"

    # Copy the latest file to the current directory with a loader/spinner
    gum spin --spinner dot --title "Copying file..." -- cp -p "$latest_file" "$current_dir"

    # Inform the user of the successful copy operation
    gum style --bold --foreground "#00FF00" "βœ… Successfully copied the latest downloaded file to the current directory!"

    # Print the final absolute path of the copied file
    gum style --bold --foreground "#FFA500" "πŸ“‚ It's here:" && gum style --italic --foreground "#00FFFF" "$current_dir"
}

grab_download

If it’s an AI generated image for a blog?

  • Another trick: from webp to png can be simply done with ffmpeg: ffmpeg -i something.webp something.png.

Daily blogging in a Confluence Corp

If you’re company is using Confluence as its knowledge base, you can do this “morning routine” to start your day right.

Notes:

  • my-company-login is whatever thing you need to do to get the SSO out of the way so it doesn’t bother your flow while you work.
  • my-company and my.company is whatever your company is.
  • 123456 is the space ID of the blog space. I’d recommend choosing the most general place with the most permissions. The whole point is to make it easy to find.
  • This script opens GitHub and JumpCloud because they were the things I had to log into through every morning, YMMV.
alias blogtitle='date "+Shay'\''s Work Blog // %Y%m%d W%W %A" | tr -d '\''\n'\'''

# Simpler version if you can't get your hands on an API key
# alias blog='blogtitle | pbcopy && open -a "Google Chrome" "https://my-company.atlassian.net/wiki/spaces/SOMESPACE/blogs"'
alias blog='curl --request POST \
  --url "https://my-company.atlassian.net/wiki/api/v2/blogposts" \
  --user "shay.nehmad@my.company:KEY" \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --data "{\"spaceId\": \"123456\", \"status\": \"draft\", \"title\": \"$(blogtitle)\"}" | jq -r "\"https://my-company.atlassian.net/wiki\" + ._links.tinyui" | pbcopy'

alias morning='echo "β˜•οΈ Good morning!" &&\
my-company-login &&\
echo "πŸ“ Opening blog..." &&\
blog && echo "$(pbpaste) copied to clipboard." &&\
echo "πŸ§‘β€πŸ’» Opening GitHub..." &&\
open -a "Google Chrome" "https://github.com/my-company/" &&\
echo "πŸ§‘β€πŸ’» Opening JumpCloud..." &&\
open -a "Google Chrome" "https://console.jumpcloud.com/login#/" &&\
echo "πŸ“š Have a productive day! Remember to zero your Email + Slack"'

Git branches cleanup

I’ve added a new alias to clean up my local branches. It’s a bit aggressive, but I like it - it makes using things like fzf-git better. It removes all branches that are merged into main except for main itself. It also prunes the remote branches.

alias git-clean-branches="git branch --merged main | grep -v -e 'main' -e '\*' | xargs -n 1 git branch -d && git remote prune origin || echo 'No local branches to remove, so nothing done.'"

This alongside other normal commands like git gc and git fetch --all --prune makes sure my git is clean, up to date, and as fast as it can be.