Skip to content

Instantly share code, notes, and snippets.

@nfitzen
Last active October 21, 2021 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfitzen/658422fc75b554b59e3c5bda7120ea9a to your computer and use it in GitHub Desktop.
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.
#!/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