148 lines
3.9 KiB
Bash
Executable File
148 lines
3.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
mkdir -p ${HOME}/.zsh_aliases.d
|
|
|
|
|
|
|
|
ALIAS_FILE=${HOME}/.zsh_aliases
|
|
cat >> ${ALIAS_FILE} <<'EOF'
|
|
|
|
# Enable .zsh_aliases.d to keep aliases separate from env variables
|
|
if [ -d ~/.zsh_aliases.d ]; then
|
|
for f (~/.zsh_aliases.d/**/*(N.)) . $f
|
|
fi
|
|
EOF
|
|
|
|
# tell bash to check the next word after the alias (i.e sudo) by adding a space to the end of the alias value.
|
|
echo "# tell bash to check the next word after the alias (i.e sudo) by adding a space to the end of the alias value." > ~/.zsh_aliases.d/002_sudo.zsh
|
|
echo 'alias sudo="sudo "' >> ~/.zsh_aliases.d/002_sudo.zsh
|
|
|
|
cat > ~/.zsh_aliases.d/003_py-aliases.zsh << 'EOF'
|
|
_py_version() {
|
|
PY_VERSIONS=(2 3)
|
|
|
|
LINE=(${(s: :)history[$HISTCMD]})
|
|
COMMAND=${LINE[1]}
|
|
ARGS=${(j: :)LINE[2,-1]}
|
|
|
|
while (( 1 )) {
|
|
read -s -k1 VERSION"?$COMMAND [${PY_VERSIONS[1]}]: "
|
|
if [[ $VERSION == $'\n' ]]; then
|
|
VERSION=${PY_VERSIONS[1]}
|
|
break
|
|
elif (( ${PY_VERSIONS[(I)$VERSION]} )); then
|
|
echo $VERSION
|
|
break
|
|
fi
|
|
echo "$VERSION is not supported (${(j:, :)PY_VERSIONS})"
|
|
}
|
|
|
|
if [[ -x $(which $COMMAND$VERSION) ]]; then
|
|
COMMAND=$COMMAND$VERSION
|
|
else
|
|
COMMAND="python$VERSION $(which -a $COMMAND | grep -v aliased | head -n 1)"
|
|
fi
|
|
eval $COMMAND $ARGS
|
|
}
|
|
|
|
# versioned python commands
|
|
alias python="_py_version"
|
|
alias pip="_py_version"
|
|
alias pydoc="_py_version"
|
|
alias idle="_py_version"
|
|
alias ipython="_py_version"
|
|
alias jupyter="_py_version"
|
|
EOF
|
|
|
|
|
|
cat > .zsh_aliases.d/003_transfer.zsh <<'EOF'
|
|
#
|
|
# Defines transfer alias and provides easy command line file and folder sharing.
|
|
#
|
|
# Authors:
|
|
# Remco Verhoef <remco@dutchcoders.io>
|
|
#
|
|
|
|
curl --version 2>&1 > /dev/null
|
|
if [ $? -ne 0 ]; then
|
|
echo "Could not find curl."
|
|
return 1
|
|
fi
|
|
|
|
transfer() {
|
|
# check arguments
|
|
if [ $# -eq 0 ];
|
|
then
|
|
echo -e "No arguments specified.\n\nUsage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
|
|
return 1
|
|
fi
|
|
|
|
# get temporarily filename, output is written to this file show progress can be showed
|
|
tmpfile=$( mktemp -t transferXXX )
|
|
|
|
# upload stdin or file
|
|
file=$1
|
|
|
|
if tty -s;
|
|
then
|
|
basefile=$(basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
|
|
|
|
if [ ! -e $file ];
|
|
then
|
|
echo "File $file doesn't exists."
|
|
return 1
|
|
fi
|
|
|
|
if [ -d $file ];
|
|
then
|
|
# zip directory and transfer
|
|
zipfile=$( mktemp -t transferXXX.zip )
|
|
cd $(dirname $file) && zip -r -q - $(basename $file) >> $zipfile
|
|
curl --progress-bar --upload-file "$zipfile" "https://transfer.sh/$basefile.zip" >> $tmpfile
|
|
rm -f $zipfile
|
|
else
|
|
# transfer file
|
|
curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> $tmpfile
|
|
fi
|
|
else
|
|
# transfer pipe
|
|
curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> $tmpfile
|
|
fi
|
|
|
|
# cat output link
|
|
cat $tmpfile
|
|
|
|
# log file link
|
|
APPLICATION="${0##*/}"
|
|
RIGHTNOW="$(date)"
|
|
EXPIRES="$(date -d "+14 days")"
|
|
echo -e "$(cat "$tmpfile") - uploaded $RIGHTNOW - expires $EXPIRES\n" >> ~/$APPLICATION.log
|
|
echo "\n\nSee ~/$APPLICATION.log for all transfers.\n"
|
|
|
|
# cleanup
|
|
rm -f $tmpfile
|
|
}
|
|
EOF
|
|
|
|
|
|
ALIAS_FILE=${HOME}/.zsh_aliases.d/003_local.sh
|
|
cat > ${ALIAS_FILE} <<'EOF'
|
|
alias locate='locate --existing --follow --basename --ignore-case'
|
|
alias wget="wget --content-disposition -c"
|
|
alias leech="wget -e robots=off -c -r --level=0 -nc -np --random-wait"
|
|
alias bc='bc -lq'
|
|
alias shred='ionice -c3 /usr/bin/shred -fuzv'
|
|
alias wipe='ionice -c3 /usr/bin/wipe -l1 -v -r'
|
|
alias less="less -R"
|
|
alias youtube-dl='youtube-dl --external-downloader=aria2c'
|
|
EOF
|
|
|
|
ALIAS_FILE=${HOME}/.zsh_aliases.d/003_lsd.sh
|
|
cat > ${ALIAS_FILE} <<'EOF'
|
|
if [ -x /usr/bin/lsd ]; then
|
|
alias lsd="/usr/bin/lsd"
|
|
alias 'ls'="lsd"
|
|
alias 'll'="lsd -a"
|
|
alias 'lt'="lsd --tree"
|
|
fi
|
|
EOF
|