Last active
October 21, 2021 01:18
-
-
Save nfitzen/658422fc75b554b59e3c5bda7120ea9a to your computer and use it in GitHub Desktop.
A Bash function that transforms a date string into Discord's Unix time format, and copies it. Requires xclip.
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
#!/usr/bin/env bash | |
# SPDX-License-Identifier: CC0-1.0 | |
# SPDX-FileCopyrightText: 2021 nfitzen <https://github.com/nfitzen> | |
# A Bash function that transforms a date string into Discord's Unix time format, and copies it. | |
# Requires xclip. Place in ~/.bash_aliases or any other Bash source. | |
function cpddate () { | |
if [ $# -eq 0 ]; then | |
>&2 echo "Not enough arguments provided." | |
return 1 | |
fi | |
if [[ -n $2 && $2 != [tTdDfFR] ]]; then | |
>&2 echo "Must use a valid Discord timestamp style." | |
return 2 | |
fi | |
string="$(date -d "$1" +'<t:%s')" | |
if [ $# -ge 2 ]; then | |
string="${string}:$2" | |
fi | |
string="${string}>" | |
echo -n "$string" | xclip -selection clipboard | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment