I know this article contains a lot of text, but trust me, it’s absolutely worth reading—you’ll become much more productive!

Fixing Incorrect File Paths

Use Case:
You encounter an incorrect file path and need to locate the issue. Instead of scrutinizing the path segment by segment, a more effective approach is to list the path and start trimming it from the end until you find the correct segment.

This method will save you mental effort and reduce eye strain.

Example:
You receive an error when attempting to open the following file:
/home/user/projects/pizza/seed/images/themes/pizza/01.jpg

To resolve the issue:

  ls -l /home/user/projects/pizza/seed/images/themes/pizza/
  ls -l /home/user/projects/pizza/seed/images/themes/
  ls -l /home/user/projects/pizza/seed/images/
  ls -l /home/user/projects/pizza/seed/
  ls -l /home/user/projects/pizza/

Then you can easily spot that the “seed” segment is not “seed” but “seeds”

final check

ls -l/home/user/projects/pizza/seeds/images/themes/pizza/01.jpg

It works!

Use finding instead of scrolling

If you need to locate something, use the “Find” shortcut instead of scrolling and reading. The “Find” command is much faster and allows you to search for variables, class names, or even partial names.

Goto Line Approximately

If your error is on line 459, you can quickly navigate there using a shortcut. Simply type a number close to 459, such as 450, and you’ll instantly see line 459 along with the numbered lines around it.

Use Code Folding

Use Case: To minimize distractions, use code folding to hide parts of the code you’re not currently working on.

Example:

In most code editors, you can collapse code blocks by clicking the small arrow next to the line numbers. This helps you focus on the part of the code you’re currently working on.

Comparing two branches

To compare two branches you can use git diff …branch-name but this will require a lot of effort.

Good way to deal with that is by cloning another copy of the repo and having two repositories locally.

Usually I have “project-name” repositor folder and “project-name-other” repository name.

Then when I want to compare I use some GUI to do the job. Mine is meld.

meld project-name/ project-name-other/

Change directory

Sometimes you want to change directory of a file. My way of doing that is to copy the current opened file path from the editor with a shortcut. Grab the whole file path in the clipboard and then do cdf … like that

cdf /home/user/some-project/some-folder/file_name.extension

Here is how cdf looks like

cdf() {
    if [ $# -eq 0 ]; then
        echo "No file path provided."
        return 1
    fi

    # Join all arguments with spaces
    local full_path="$*"


    if [ -f "$full_path" ]; then
        # If it's a file, extract the directory path
        local dir_path
        dir_path=$(dirname "$full_path")
    elif [ -d "$full_path" ]; then
        # If it's a directory, use it directly
        local dir_path="$full_path"
    else
        echo "The path provided is neither a file nor a directory."
        return 1
    fi


    # Change to the directory
    cd "$dir_path" || {
        echo "Failed to change directory to $dir_path"
        return 1
    }
}