Fixing wrong paths
Use case: You have a wrong path to a file. Instead of staring at the path and reading it segment by segment, the bext way is to list that path and start deleting from the end until you got the right segment.
This method will save you brain cells and eye power.
Example:
The error is on opening file: “/home/user/projects/pizza/seed/images/themes/pizza/01.jpg”
To fix it do
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 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 finding
If you have to search something use the find Shortcut instead of scrolling and reading. The “Find” command is faster than you and you can use it with variable, class names and more. Even you can search for part of the name
Goto Line Approximately
If your error is on line 459, to go there you can just use shortcut and then type a number around 459.
There would be no problem to type 450 and then you will instantly see 459 from your numbered lines.
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
}
}