Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Friday, 19 April 2024

Adding repo name to bash prompt string

Overriding the custom prompt

To overwrite the default bash prompt string, also known as PS1(prompt string one), create a file name at ~/.config/git/git-prompt.sh

e.g. C:/Users/ItsMe/.config/git/git-prompt.sh

You'll need to set a variable named PS1. Here's a very simple example of a custom prompt of "hello" followed by a newline and the classic '$' symbol:

PS1="hello\n$ "



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...