Monday, 18 February 2019

Script to remove all local git branches that have been merged


This is a bash script that removes all local git branches if:
- they have been merged
- they are not called develop
- they are not called master

It lists the branches and prompts me to confirm the list before the deleting starts.

deleting my local branches using the script

The script:

function remove_branches {
  echo "Removing all merged local branches!!!"
  for k in $(git branch --merged  | sed /\*/d); do 
    if [ -z $(echo $k | grep -i 'master\|develop') ]; then
      git branch -D $k
    fi
  done
exit
}


# Print branches to be deleted
for k in $(git branch --merged | sed /\*/d); do 
  if [ -z $(echo $k | grep -i 'master\|develop') ]; then
      echo $k
  fi
done


# Prompt user to delete branches
while true; do
read -p "Do you wish to remove these branches?" yn
case $yn in
[Yy]* ) remove_branches;;
[Nn]* ) echo "okay."; exit;;
* ) echo "Please answer yes or no."
esac
done

Friday, 1 February 2019

Bash command batch for renaming files without prefix


This line renames all files in a directory to remove the front of their names up to and including the first underscore character.
e.g.:
1242_file.txt
1209_another_file.txt
99_red balloons.wav

~becomes~

file.txt
another_file.txt
red balloons.wav


for i in *; do mv "$i" "`echo "$i" | sed 's/^[^_]*_//'`"; done

  Azure Trusted Signing Signtool Error SignTool Error: An unexpected internal error has occurred. Error information: "Error: SignerSign...