bash dd confirmation function/alias for those who need it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dd () { | |
local bold=$(tput bold) | |
local normal=$(tput sgr0) | |
local red=$(tput setaf 1) | |
local green=$(tput setaf 2) | |
local yellow=$(tput setaf 3) | |
local ddcommand=$(which dd) | |
local vars="" | |
for var in "$@" | |
do | |
eval local $var; | |
vars="$vars $var" | |
done | |
if [ -z ${status+x} ]; then vars="$vars status=progress"; | |
if [ -z ${if+x} ]; then echo "${bold}${red}No input specified!${normal}"; fi | |
else | |
echo "${bold}${green}Input: $if${normal}"; | |
if [[ $if == *"/dev/"* ]]; then | |
fdisk -l $if | |
else | |
ls -l $if | |
fi | |
fi | |
if [ -z ${of+x} ]; then echo "${bold}${red}No output specified!${normal}"; | |
else | |
echo "${bold}${yellow}Output: $of${normal}"; | |
if [[ $of == *"/dev/"* ]]; then | |
fdisk -l $of | |
else | |
ls -l $of | |
fi | |
fi | |
echo "${bold}${yellow}Command: $of${normal}"; | |
echo "$ddcommand$vars" | |
read -r -p "${bold}${red}Are you sure? [y/N]${normal} " response | |
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]] | |
then | |
$ddcommand$vars | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment