Skip to content

Instantly share code, notes, and snippets.

@andkirby
andkirby / slack.sh
Last active April 4, 2024 17:51
Shell/Bash script for sending slack messages.
#!/usr/bin/env bash
####################################################################################
# Slack Bash console script for sending messages.
####################################################################################
# Installation
# $ curl -s https://gist.githubusercontent.com/andkirby/67a774513215d7ba06384186dd441d9e/raw --output /usr/bin/slack
# $ chmod +x /usr/bin/slack
####################################################################################
# USAGE
# Send message to slack channel/user
@andkirby
andkirby / semversort.sh
Last active January 12, 2024 15:28
Semantic versions sorting in bash.
#!/usr/bin/env bash
# Download this gist
# curl -Ls https://gist.github.com/andkirby/54204328823febad9d34422427b1937b/raw/semversort.sh | bash
# And run:
# $ semversort 1.0 1.0-rc 1.0-patch 1.0-alpha
# or in GIT
# $ semversort $(git tag)
# Using pipeline:
# $ echo 1.0 1.0-rc 1.0-patch 1.0-alpha | semversort
#
@andkirby
andkirby / php-git-bash-win.sh
Last active December 31, 2023 12:21
Download PHP binaries archive on Windows from GitBash console or similar
#!/usr/bin/env bash
################################################################################
# This script can install PHP binaries on Windows in Bash.
#
# Link to this file:
# https://gist.github.com/andkirby/67e87e319c376b8676d559edb759e3fe/raw/php-git-bash-win.sh
#
# Download latest version by command in GitBash Windows console:
# $ curl -Ls bit.ly/php-bash-win | bash
#
@andkirby
andkirby / bashrc_ps1_install.sh
Last active March 19, 2023 19:25
Install colorization for PS1 in bash.
#!/usr/bin/env bash
###################################
# PS1 color for .bashrc file
#
# curl -Ls https://gist.github.com/andkirby/389f18642fc08d1b0711d17978445f2b/raw/bashrc_ps1_install.sh | bash
# curl -Ls https://bit.ly/bash-ps1 | bash
###################################
touch ~/.bashrc
if ! cat ~/.bashrc | grep '# Colorize PS1 console' > /dev/null; then
echo >> ~/.bashrc
@andkirby
andkirby / version_sort.php
Last active October 4, 2022 09:54
Semantic versions sorting
<?php
/**
* Sort versions list
*
* Add an alias in GIT
* $ git config --global alias.tags "!git tag | xargs -i -0 php "$(where version_sort)" {}"
* @link https://gist.github.com/andkirby/0046df5cad44f86b670a102b7c8b7ba7
*/
try {
if (php_sapi_name() != 'cli') {
@andkirby
andkirby / node-npm-git-bash-win.sh
Last active April 29, 2022 14:07
Download and install node latest NodeJS and Npm on Windows (shell: Git Bash or similar).
#!/usr/bin/env bash
# This script can install NodeJS and NPM on Windows
# Run this command in GitBash Windows console to get latest version:
#
# $ curl -Ls https://gist.github.com/andkirby/raw/node-npm-git-bash-win.sh | bash
#
# Last update: 2022-04-29
set -o errexit
set -o pipefail
@andkirby
andkirby / revert_config_dump.sh
Last active October 2, 2020 14:50
Remove added data after `magento app:config:dump`
php -r '$config = require "app/etc/config.php"; \
$config = ["modules" => $config["modules"]]; \
echo "<?php\nreturn "; var_export($config); \
echo ";";' \
> app/etc/config.php.cleaned && mv app/etc/config.php.cleaned app/etc/config.php
php -r '$config = require "app/etc/env.php"; \
unset($config["system"]); \
echo "<?php\nreturn "; \
var_export($config); \
@andkirby
andkirby / ssh_config_merge.sh
Last active October 1, 2020 11:37
Merge ssh split config files into end ~/.ssh/config.
################################################################################
# This script can merge all split SSH configuration into `~/.ssh/config` file.
#
# HOW IT WORKS
# It will merge all files by mask config.*.merge, i.e.:
# ~/.ssh/config.MY_PROJECT.merge
# Initial exists `~/.ssh/config` file will be copied to `~/.ssh/config.orig`.
# Use this `config.orig` for further changes.
#
# Anyway, you may not use this script and just run:
@andkirby
andkirby / reset_time_on_ssh_login.sh
Last active August 19, 2020 11:07
Reset time on ssh login in a Unix system
########################################
# Reset time on login #
########################################
# you may try to use system last logged time: `last ${USER} -n1 | head -1 | awk '{print $4" "$5" "$6" "$7}'`
time_sync_command='sudo ntpdate -s time.nist.gov'
# max time not logged value
not_logged_max_time_h=6
@andkirby
andkirby / sync_ssh_files_wsl_ubuntu
Created August 19, 2020 08:04
Synchronize .ssh files from Windows file system to Ubuntu WSL
#!/usr/bin/env bash
##################################################################
# Synchronize .ssh files from Windows file system to Ubuntu WSL #
##################################################################
set -o pipefail
set -o errexit
set -o nounset
#set -o xtrace
# Set magic variables for current file & dir