# run command inside the root directory of the project to bundle including all branches
git bundle create reponame.bundle --all
# to bundle only the main branch
git bundle create reponame.bundle main
# to unbundle, use the following command
git clone reponame.bundle
# after cloning, you will see the bundle is set as default remote repository origin
git remote -v
> origin /home/user/projects/reponame.bundle (fetch)
> origin /home/user/projects/reponame.bundle (push)
# if you want to add a new remote repo as origin, you first have to remove the current origin repository, but this means loosing access to your branches etc.
git remote rm origin
# alternatively, you can provide a new name while cloning
git clone --origin <new_name> reponame.bundle
Category: Terminal
[Terminal] My traceroute (MTR)
Just learned about My traceroute, which combines the functions of the traceroute and ping programs in one tool. Really handy!
sudo apt install mtr
mtr wikipedia.org
[Terminal] Bash script to add leading season and episode numbers by parsing from file names
I had some videos in the format “My Episode #01.mkv” which I wanted to rename to “S01E01 My Episode #01.mkv“. This little script did the job for me:
# Specify the directory containing the files. For current directory use: $(dirname "$0")
directory="/path/to/your/directory"
# Loop through all .mkv files in the directory
for file in "$directory"/*.{webm,mkv}; do
# Check if the file exists to avoid errors when no files match
[ -e "$file" ] || continue
# Extract the base filename (without the directory path)
filename=$(basename "$file")
# Use regex to find the episode number (e.g., #01, #02)
if [[ $filename =~ \#([0-9]+) ]]; then
episode_number=${BASH_REMATCH[1]}
# Pad the episode number with a leading zero if it's a single digit
if [ ${#episode_number} -eq 1 ]; then
episode_number="0$episode_number"
fi
# Construct the new filename
new_filename="S01E${episode_number} $filename"
# Rename the file
mv "$file" "$directory/$new_filename"
echo "Renamed: $filename -> $new_filename"
fi
done
[Git] Branch Commands
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
https://git-scm.com/book/en/v2/Git-Branching-Branch-Management
# create branch, switch to it and commit changes
git checkout -b hotfix
git commit -a -m 'Commit changes for fix'
# go back to main branch
git checkout main
# merge branch changes to main
git merge hotfix
# delete branch after merging, as it is not needed anymore
git branch -d hotfix
# check on which branch your are
git status
# list all branches including last commit on each branch
git branch -vv
# check which branches are already merged and which are not
git branch --merged
git branch --no-merged
# rename branche locally
git branch --move bad-branch-name corrected-branch-name
# push new name to github/gitlab
git push --set-upstream origin corrected-branch-name
# displays local and remote branches
git branch --all
# delete remote branch
git push origin --delete bad-branch-name
# push branch to remote
git push origin hotfix
[Git] Error on Windows using VSCode Dev Container
After connecting to a local dev container using Visual Studio Code and trying to clone a private project from Github I got the following error:
Cloning into 'myProject'...
warning: url has no scheme: helperselector
fatal: credential url cannot be parsed: helperselector
The only way I could remove this error was deleting the helperselector settings. So open the git config with:
git config --edit --global

and remove the the helperselector block (the first two lines). You will now get asked again for your credentials when cloning a project.
[Terminal] Using rsync with –backup and –delete together
I’m using rsync to create backups from my NAS to an external HDD. The command looks like this:
rsync -azP --delete --exclude=/.zfs -b --backup-dir=Backup /mnt/nfs/photos/ /media/nocin/externalBackup/photos/
rsync parameter | description |
-a –archive | This is equivalent to -rlptgoD. It is a quick way of saying you want recursion and want to preserve almost everything. |
-z –compress | With this option, rsync compresses the file data as it is sent to the destination machine, which reduces the amount of data being transmitted |
-P | The -P option is equivalent to –partial –progress. Its purpose is to make it much easier to specify these two options for a long transfer that may be interrupted. |
–delete | This tells rsync to delete extraneous files from the receiving side (ones that aren’t on the sending side) |
–exclude | exclude files matching PATTERN |
-b –backup-dir | With this option preexisting destination files are renamed with a ~ extension as each file is transferred. You can control where the backup file goes and what (if any) suffix gets appended using the –backup-dir and –suffix options. |
But somehow it always created the Backup folder recursively again inside the Backup folder. So the first run created the /Backup folder, after the second run I’ve got /Backup/Backup, after the third run /Backup/Backup/Backup and so on..
The solution was to exclude the Backup directory using the --exclude
command.
rsync -azP --delete --exclude=/.zfs --exclude=Backup -b --backup-dir=Backup /mnt/nfs/photos/ /media/nocin/externalBackup/photos/
I found a good explanation for this behaviour here: https://www.jveweb.net/en/archives/2011/02/using-rsync-and-cron-to-automate-incremental-backups.html
“If we are storing backups in the destination folder, or in a directory inside of the destination folder, the --delete
parameter is going to delete old backups, as they are not in the source folder. Or attempt to as in the following situation:
Say, we already have a folder called backup inside of the destination directory, and we use rsync
again, using --backup-dir=backup
one more time. As rsync
is going to attempt to delete every file and folder that is not in the source directory, it would backup the backup folder, which would create a backup folder inside our already existing backup folder, and then it would attempt to delete the backup folder and fail because it is using it to backup files.”
[Terminal] F2 – Command-line batch renaming tool
Project: https://github.com/ayoisaiah/f2
Wiki: https://github.com/ayoisaiah/f2/wiki
Installation: https://github.com/ayoisaiah/f2/wiki/Installation
curl -LO https://github.com/ayoisaiah/f2/releases/download/v1.6.1/f2_1.6.1_linux_amd64.tar.gz
tar -xvzf f2_1.6.1_linux_amd64.tar.gz
chmod +x f2
sudo mv f2 /usr/local/bin
rm f2_1.6.1_linux_amd64.tar.gz
Renaming a file from ‘img’ to ‘Image’
# test run
f2 -f 'img' -r 'Image'
# performing the actual renaming
f2 -f 'img' -r 'Image' -x
# undo the changes
f2 -u -x
Or renaming episodes from 01_S1.MyEpisode.mp4
to S01E01.MyEpisode.mp4
f2 -f '.._S1' -r 'S01E%02d'
[Linux Mint] Install PyWal on Linux Mint 20.1 Cinnamon
“Pywal is a tool that generates a color palette from the dominant colors in an image. It then applies the colors system-wide and on-the-fly in all of your favorite programs.”
https://github.com/dylanaraps/pywal/wiki/Installation
pip3 install pywal
I’m using Variety to change my wallpaper every day automatically. To always get the right colors in my terminal I added some lines in my .zshrc that will always grab the current wallpaper and pass it to PyWal. I’m sure a bash pro would do this in just one line… 🙂
#---PyWal---#
# load previous theme
(cat ~/.cache/wal/sequences &)
# get picture path
picturepath=$(gsettings get org.gnome.desktop.background picture-uri)
# remove prefix & suffix
prefix="'file://"
suffix="'"
picturepath=${picturepath#"$prefix"}
picturepath=${picturepath%"$suffix"}
# set colors
wal -n -q -i "$picturepath"
#---PyWal End---#
There are many plugins/tools you can combine with PyWal:
https://github.com/frewacom/pywalfox