Skip to content

Instantly share code, notes, and snippets.

View anikolaienko's full-sized avatar

Andrii Nikolaienko anikolaienko

View GitHub Profile
@anikolaienko
anikolaienko / github_repo_admins_list.sh
Last active August 24, 2022 08:36
Get list of Github repo Admins
# Check all page numbers starting 1 until result is empty
curl "https://api.github.com/repos/ORG/REPO/collaborators?per_page=100&page=1" -H "Authorization: Token ACCESS_TOKEN" | \
jq '[ .[] | select(.permissions.admin == true) | .html_url ]'
@anikolaienko
anikolaienko / git_list_branches_sorted_updated.sh
Created May 31, 2022 16:17
Git list branches sorted by last update date
git for-each-ref --sort=-committerdate refs/heads --format='%(authordate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset))'
@anikolaienko
anikolaienko / git_branch_rm_merged.sh
Created May 30, 2022 13:52
Git - remove already merged branches
git branch --merged master | grep -v '^[ *]*master$' | xargs git branch -d
@anikolaienko
anikolaienko / run_cmd_foreach_line_in_file.sh
Created April 27, 2022 16:02
Run command for each line in file
#!/bin/bash
# Example: run_cmd_foreach_line_in_file.sh command file_with_lines.txt
echo Start
while read p; do
$1 $p
done < $2
@anikolaienko
anikolaienko / drop_line_with_text.sh
Last active April 27, 2022 16:01
Drop lines with certain text from file
if [ "$#" -ne 2 ]; then
echo "Illegal number of parameters"
return
fi
cat $1 | grep -v $2 > "$1_tmp" && mv "$1_tmp" $1
@anikolaienko
anikolaienko / generate_random_content_large_file.md
Last active January 21, 2022 10:38
Bash: Generate random content large file

Size:

  • 2**10 - 1 KB
  • 2**20 - 1 MB
  • 2**30 - 1 GB

1) Using openssl util

use -base64 flag to generate readable content

@anikolaienko
anikolaienko / read_folder_path_until_valid.sh
Created December 30, 2021 16:51
Bash: Read folder path until valid
# Accept either empty path or valid path
while [ -z $path_confirm ]; do
read -rp 'Type folder path (relative to current):' folder_path
path_confirm="y"
if [ ! -z $folder_path ] && [[ ! -d $folder_path ]]; then
read -rp 'Path does not exist. Do you want to type it again? [y/n]:' path_confirm