From a103fbddbe98f74d09604376457b54720f3d89bb Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Tue, 15 Aug 2023 12:10:36 +0300 Subject: [PATCH] feat(tools): moved x-dc & few others to shared.sh --- base/zshrc | 25 +++++++++++++------------ config/functions | 24 ------------------------ local/bin/x-dc | 13 ------------- scripts/shared.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 49 deletions(-) delete mode 100755 local/bin/x-dc diff --git a/base/zshrc b/base/zshrc index 342a76c..1853795 100644 --- a/base/zshrc +++ b/base/zshrc @@ -13,6 +13,19 @@ export DOTFILES="$HOME/.dotfiles" # shellcheck source=shared.sh source "$DOTFILES/scripts/shared.sh" +# Run x-load-configs in your terminal to reload the files. +function x-load-configs() +{ + # Load the shell dotfiles, and then some: + for file in $DOTFILES/config/{exports,alias,functions}; do + [ -r "$file" ] && source "$file" + [ -r "$file-secret" ] && source "$file-secret" + [ -r "$file-$HOSTNAME" ] && source "$file-$HOSTNAME" + [ -r "$file-$HOSTNAME-secret" ] && source "$file-$HOSTNAME-secret" + done +} +x-load-configs + export HISTFILE="$XDG_STATE_HOME"/zsh/history autoload -U colors zsh/terminfo @@ -33,18 +46,6 @@ then compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION" fi -# Run x-load-configs in your terminal to reload the files. -function x-load-configs() -{ - # Load the shell dotfiles, and then some: - for file in $DOTFILES/config/{exports,alias,functions}; do - [ -r "$file" ] && source "$file" - [ -r "$file-secret" ] && source "$file-secret" - [ -r "$file-$HOSTNAME" ] && source "$file-$HOSTNAME" - [ -r "$file-$HOSTNAME-secret" ] && source "$file-$HOSTNAME-secret" - done -} -x-load-configs # Import ssh keys in keychain ssh-add -A 2>/dev/null; diff --git a/config/functions b/config/functions index e879388..bcf12d5 100755 --- a/config/functions +++ b/config/functions @@ -20,12 +20,6 @@ ssh-docker() docker exec -it "$@" bash } -# Create a new directory and enter it -mkd() -{ - mkdir -p "$@" && cd "$@" || exit -} - # All the dig info digga() { @@ -64,24 +58,6 @@ scheduler() done } -silent() -{ - "$@" >&/dev/null -} - -ask() -{ - while true; do - read -p "$1 ([y]/n) " -r - REPLY=${REPLY:-"y"} - if [[ $REPLY =~ ^[Yy]$ ]]; then - return 1 - elif [[ $REPLY =~ ^[Nn]$ ]]; then - return 0 - fi - done -} - # Defines default antigen bundles x-default-antigen-bundles() { diff --git a/local/bin/x-dc b/local/bin/x-dc deleted file mode 100755 index 023d9b5..0000000 --- a/local/bin/x-dc +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# Verify folder exists, and if it does not, create it. - -dir="$1" - -[ $# -eq 0 ] && { - echo "Usage: $0 full/path/to/dir/to/create" - exit 1 -} - -if [ ! -d "$dir" ]; then - mkdir -p "$dir" && exit 0 -fi diff --git a/scripts/shared.sh b/scripts/shared.sh index 8cb8e4b..e129be5 100755 --- a/scripts/shared.sh +++ b/scripts/shared.sh @@ -294,3 +294,46 @@ function replacable() return 1 } + +# Create directory if it doesn't exist already +x-dc() +{ + dir="$1" + + [ $# -eq 0 ] && { + echo "Usage: $0 full/path/to/dir/to/create" + exit 1 + } + + if [ ! -d "$dir" ]; then + mkdir -p "$dir" && exit 0 + fi +} + +# Create a new directory and enter it +mkd() +{ + mkdir -p "$@" && cd "$@" || exit +} + +# Run command silently +# Usage: silent uptime +silent() +{ + "$@" >&/dev/null +} + +# Create a prompt which you have to answer y/n to continue +ask() +{ + while true; do + read -p "$1 ([y]/n) " -r + REPLY=${REPLY:-"y"} + if [[ $REPLY =~ ^[Yy]$ ]]; then + return 1 + elif [[ $REPLY =~ ^[Nn]$ ]]; then + return 0 + fi + done +} +