From 2402b4d2cfc7a22885ac5317218bdd9884bc135c Mon Sep 17 00:00:00 2001 From: T31M Date: Sat, 22 Feb 2020 21:33:54 +0100 Subject: [PATCH] feat: deletions --- admin/iptables_logging | 32 -- boilersplate.sh | 393 ------------------ javascript_typescript/logging.js | 71 ---- shell/dot.config/fish/config.fish | 2 - shell/dot.config/fish/fishfile | 5 - .../fish/functions/fish_prompt.fish | 70 ---- .../fish/functions/fish_right_prompt.fish | 142 ------- shell/dot.vimrc | 15 - shell/fish_setup.sh | 18 - 9 files changed, 748 deletions(-) delete mode 100644 admin/iptables_logging delete mode 100644 boilersplate.sh delete mode 100644 javascript_typescript/logging.js delete mode 100644 shell/dot.config/fish/config.fish delete mode 100644 shell/dot.config/fish/fishfile delete mode 100644 shell/dot.config/fish/functions/fish_prompt.fish delete mode 100644 shell/dot.config/fish/functions/fish_right_prompt.fish delete mode 100644 shell/dot.vimrc delete mode 100644 shell/fish_setup.sh diff --git a/admin/iptables_logging b/admin/iptables_logging deleted file mode 100644 index dabbaa2..0000000 --- a/admin/iptables_logging +++ /dev/null @@ -1,32 +0,0 @@ -#log all dropped packages to separate file - -#backup -sudo iptables-save > backup.save - -#safety flush cronjob every xx:45h -sudo crontab -e -45 * * * * /sbin/iptables -F - -#begin -sudo iptables -N DROP_AND_LOG -sudo iptables -A DROP_AND_LOG -m limit --limit 1/min -j LOG --log-prefix "[IPTABLES-DROP]: " -sudo iptables -A DROP_AND_LOG -j DROP - -#if old rules exist, save now upated rules -sudo iptables-save > modded.save - -#replace DROP with DROP_AND_LOG chain -sed -e 's:-j DROP:-j DROP_AND_LOG:g' modded.save > replaced.save - -#fix last "-j DROP" to original... -vim replaced.save - -#create custom syslog output log -vim /etc/rsyslog.d/custom_iptables.conf -> :msg,contains,"IPTABLES-DROP" /var/log/iptables.log - -#flush iptables and restore our modded rules -sudo iptables -F -sudo iptables-restore < replaced.save - -#see the magic happen... (and dont forget to remove cronjob...) diff --git a/boilersplate.sh b/boilersplate.sh deleted file mode 100644 index fec3475..0000000 --- a/boilersplate.sh +++ /dev/null @@ -1,393 +0,0 @@ -#!/usr/bin/env bash -# This file: -# -# - Demos BASH3 Boilerplate (change this for your script) -# -# Usage: -# -# LOG_LEVEL=7 ./main.sh -f /tmp/x -d (change this for your script) -# -# Based on a template by BASH3 Boilerplate v2.3.0 -# http://bash3boilerplate.sh/#authors -# -# The MIT License (MIT) -# Copyright (c) 2013 Kevin van Zonneveld and contributors -# You are not obligated to bundle the LICENSE file with your b3bp projects as long -# as you leave these references intact in the header comments of your source files. - -# Exit on error. Append "|| true" if you expect an error. -set -o errexit -# Exit on error inside any functions or subshells. -set -o errtrace -# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR -set -o nounset -# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip` -set -o pipefail -# Turn on traces, useful while debugging but commented out by default -# set -o xtrace - -if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then - __i_am_main_script="0" # false - - if [[ "${__usage+x}" ]]; then - if [[ "${BASH_SOURCE[1]}" = "${0}" ]]; then - __i_am_main_script="1" # true - fi - - __b3bp_external_usage="true" - __b3bp_tmp_source_idx=1 - fi -else - __i_am_main_script="1" # true - [[ "${__usage+x}" ]] && unset -v __usage - [[ "${__helptext+x}" ]] && unset -v __helptext -fi - -# Set magic variables for current file, directory, os, etc. -__dir="$(cd "$(dirname "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")" && pwd)" -__file="${__dir}/$(basename "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")" -__base="$(basename "${__file}" .sh)" - - -# Define the environment variables (and their defaults) that this script depends on -LOG_LEVEL="${LOG_LEVEL:-6}" # 7 = debug -> 0 = emergency -NO_COLOR="${NO_COLOR:-}" # true = disable color. otherwise autodetected - - -### Functions -############################################################################## - -function __b3bp_log () { - local log_level="${1}" - shift - - # shellcheck disable=SC2034 - local color_debug="\x1b[35m" - # shellcheck disable=SC2034 - local color_info="\x1b[32m" - # shellcheck disable=SC2034 - local color_notice="\x1b[34m" - # shellcheck disable=SC2034 - local color_warning="\x1b[33m" - # shellcheck disable=SC2034 - local color_error="\x1b[31m" - # shellcheck disable=SC2034 - local color_critical="\x1b[1;31m" - # shellcheck disable=SC2034 - local color_alert="\x1b[1;33;41m" - # shellcheck disable=SC2034 - local color_emergency="\x1b[1;4;5;33;41m" - - local colorvar="color_${log_level}" - - local color="${!colorvar:-${color_error}}" - local color_reset="\x1b[0m" - - if [[ "${NO_COLOR:-}" = "true" ]] || ( [[ "${TERM:-}" != "xterm"* ]] && [[ "${TERM:-}" != "screen"* ]] ) || [[ ! -t 2 ]]; then - if [[ "${NO_COLOR:-}" != "false" ]]; then - # Don't use colors on pipes or non-recognized terminals - color=""; color_reset="" - fi - fi - - # all remaining arguments are to be printed - local log_line="" - - while IFS=$'\n' read -r log_line; do - echo -e "$(date -u +"%Y-%m-%d %H:%M:%S UTC") ${color}$(printf "[%9s]" "${log_level}")${color_reset} ${log_line}" 1>&2 - done <<< "${@:-}" -} - -function emergency () { __b3bp_log emergency "${@}"; exit 1; } -function alert () { [[ "${LOG_LEVEL:-0}" -ge 1 ]] && __b3bp_log alert "${@}"; true; } -function critical () { [[ "${LOG_LEVEL:-0}" -ge 2 ]] && __b3bp_log critical "${@}"; true; } -function error () { [[ "${LOG_LEVEL:-0}" -ge 3 ]] && __b3bp_log error "${@}"; true; } -function warning () { [[ "${LOG_LEVEL:-0}" -ge 4 ]] && __b3bp_log warning "${@}"; true; } -function notice () { [[ "${LOG_LEVEL:-0}" -ge 5 ]] && __b3bp_log notice "${@}"; true; } -function info () { [[ "${LOG_LEVEL:-0}" -ge 6 ]] && __b3bp_log info "${@}"; true; } -function debug () { [[ "${LOG_LEVEL:-0}" -ge 7 ]] && __b3bp_log debug "${@}"; true; } - -function help () { - echo "" 1>&2 - echo " ${*}" 1>&2 - echo "" 1>&2 - echo " ${__usage:-No usage available}" 1>&2 - echo "" 1>&2 - - if [[ "${__helptext:-}" ]]; then - echo " ${__helptext}" 1>&2 - echo "" 1>&2 - fi - - exit 1 -} - - -### Parse commandline options -############################################################################## - -# Commandline options. This defines the usage page, and is used to parse cli -# opts & defaults from. The parsing is unforgiving so be precise in your syntax -# - A short option must be preset for every long option; but every short option -# need not have a long option -# - `--` is respected as the separator between options and arguments -# - We do not bash-expand defaults, so setting '~/app' as a default will not resolve to ${HOME}. -# you can use bash variables to work around this (so use ${HOME} instead) - -# shellcheck disable=SC2015 -[[ "${__usage+x}" ]] || read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered - -f --file [arg] Filename to process. Required. - -t --temp [arg] Location of tempfile. Default="/tmp/bar" - -v Enable verbose mode, print script as it is executed - -d --debug Enables debug mode - -h --help This page - -n --no-color Disable color output - -1 --one Do just one thing -EOF - -# shellcheck disable=SC2015 -[[ "${__helptext+x}" ]] || read -r -d '' __helptext <<-'EOF' || true # exits non-zero when EOF encountered - This is Bash3 Boilerplate's help text. Feel free to add any description of your - program or elaborate more on command-line arguments. This section is not - parsed and will be added as-is to the help. -EOF - -# Translate usage string -> getopts arguments, and set $arg_ defaults -while read -r __b3bp_tmp_line; do - if [[ "${__b3bp_tmp_line}" =~ ^- ]]; then - # fetch single character version of option string - __b3bp_tmp_opt="${__b3bp_tmp_line%% *}" - __b3bp_tmp_opt="${__b3bp_tmp_opt:1}" - - # fetch long version if present - __b3bp_tmp_long_opt="" - - if [[ "${__b3bp_tmp_line}" = *"--"* ]]; then - __b3bp_tmp_long_opt="${__b3bp_tmp_line#*--}" - __b3bp_tmp_long_opt="${__b3bp_tmp_long_opt%% *}" - fi - - # map opt long name to+from opt short name - printf -v "__b3bp_tmp_opt_long2short_${__b3bp_tmp_long_opt//-/_}" '%s' "${__b3bp_tmp_opt}" - printf -v "__b3bp_tmp_opt_short2long_${__b3bp_tmp_opt}" '%s' "${__b3bp_tmp_long_opt//-/_}" - - # check if option takes an argument - if [[ "${__b3bp_tmp_line}" =~ \[.*\] ]]; then - __b3bp_tmp_opt="${__b3bp_tmp_opt}:" # add : if opt has arg - __b3bp_tmp_init="" # it has an arg. init with "" - printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "1" - elif [[ "${__b3bp_tmp_line}" =~ \{.*\} ]]; then - __b3bp_tmp_opt="${__b3bp_tmp_opt}:" # add : if opt has arg - __b3bp_tmp_init="" # it has an arg. init with "" - # remember that this option requires an argument - printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "2" - else - __b3bp_tmp_init="0" # it's a flag. init with 0 - printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "0" - fi - __b3bp_tmp_opts="${__b3bp_tmp_opts:-}${__b3bp_tmp_opt}" - fi - - [[ "${__b3bp_tmp_opt:-}" ]] || continue - - if [[ "${__b3bp_tmp_line}" =~ (^|\.\ *)Default= ]]; then - # ignore default value if option does not have an argument - __b3bp_tmp_varname="__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" - - if [[ "${!__b3bp_tmp_varname}" != "0" ]]; then - __b3bp_tmp_init="${__b3bp_tmp_line##*Default=}" - __b3bp_tmp_re='^"(.*)"$' - if [[ "${__b3bp_tmp_init}" =~ ${__b3bp_tmp_re} ]]; then - __b3bp_tmp_init="${BASH_REMATCH[1]}" - else - __b3bp_tmp_re="^'(.*)'$" - if [[ "${__b3bp_tmp_init}" =~ ${__b3bp_tmp_re} ]]; then - __b3bp_tmp_init="${BASH_REMATCH[1]}" - fi - fi - fi - fi - - if [[ "${__b3bp_tmp_line}" =~ (^|\.\ *)Required\. ]]; then - # remember that this option requires an argument - printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "2" - fi - - printf -v "arg_${__b3bp_tmp_opt:0:1}" '%s' "${__b3bp_tmp_init}" -done <<< "${__usage:-}" - -# run getopts only if options were specified in __usage -if [[ "${__b3bp_tmp_opts:-}" ]]; then - # Allow long options like --this - __b3bp_tmp_opts="${__b3bp_tmp_opts}-:" - - # Reset in case getopts has been used previously in the shell. - OPTIND=1 - - # start parsing command line - set +o nounset # unexpected arguments will cause unbound variables - # to be dereferenced - # Overwrite $arg_ defaults with the actual CLI options - while getopts "${__b3bp_tmp_opts}" __b3bp_tmp_opt; do - [[ "${__b3bp_tmp_opt}" = "?" ]] && help "Invalid use of script: ${*} " - - if [[ "${__b3bp_tmp_opt}" = "-" ]]; then - # OPTARG is long-option-name or long-option=value - if [[ "${OPTARG}" =~ .*=.* ]]; then - # --key=value format - __b3bp_tmp_long_opt=${OPTARG/=*/} - # Set opt to the short option corresponding to the long option - __b3bp_tmp_varname="__b3bp_tmp_opt_long2short_${__b3bp_tmp_long_opt//-/_}" - printf -v "__b3bp_tmp_opt" '%s' "${!__b3bp_tmp_varname}" - OPTARG=${OPTARG#*=} - else - # --key value format - # Map long name to short version of option - __b3bp_tmp_varname="__b3bp_tmp_opt_long2short_${OPTARG//-/_}" - printf -v "__b3bp_tmp_opt" '%s' "${!__b3bp_tmp_varname}" - # Only assign OPTARG if option takes an argument - __b3bp_tmp_varname="__b3bp_tmp_has_arg_${__b3bp_tmp_opt}" - printf -v "OPTARG" '%s' "${@:OPTIND:${!__b3bp_tmp_varname}}" - # shift over the argument if argument is expected - ((OPTIND+=__b3bp_tmp_has_arg_${__b3bp_tmp_opt})) - fi - # we have set opt/OPTARG to the short value and the argument as OPTARG if it exists - fi - __b3bp_tmp_varname="arg_${__b3bp_tmp_opt:0:1}" - __b3bp_tmp_default="${!__b3bp_tmp_varname}" - - __b3bp_tmp_value="${OPTARG}" - if [[ -z "${OPTARG}" ]] && [[ "${__b3bp_tmp_default}" = "0" ]]; then - __b3bp_tmp_value="1" - fi - - printf -v "${__b3bp_tmp_varname}" '%s' "${__b3bp_tmp_value}" - debug "cli arg ${__b3bp_tmp_varname} = (${__b3bp_tmp_default}) -> ${!__b3bp_tmp_varname}" - done - set -o nounset # no more unbound variable references expected - - shift $((OPTIND-1)) - - if [[ "${1:-}" = "--" ]] ; then - shift - fi -fi - - -### Automatic validation of required option arguments -############################################################################## - -for __b3bp_tmp_varname in ${!__b3bp_tmp_has_arg_*}; do - # validate only options which required an argument - [[ "${!__b3bp_tmp_varname}" = "2" ]] || continue - - __b3bp_tmp_opt_short="${__b3bp_tmp_varname##*_}" - __b3bp_tmp_varname="arg_${__b3bp_tmp_opt_short}" - [[ "${!__b3bp_tmp_varname}" ]] && continue - - __b3bp_tmp_varname="__b3bp_tmp_opt_short2long_${__b3bp_tmp_opt_short}" - printf -v "__b3bp_tmp_opt_long" '%s' "${!__b3bp_tmp_varname}" - [[ "${__b3bp_tmp_opt_long:-}" ]] && __b3bp_tmp_opt_long=" (--${__b3bp_tmp_opt_long//_/-})" - - help "Option -${__b3bp_tmp_opt_short}${__b3bp_tmp_opt_long:-} requires an argument" -done - - -### Cleanup Environment variables -############################################################################## - -for __tmp_varname in ${!__b3bp_tmp_*}; do - unset -v "${__tmp_varname}" -done - -unset -v __tmp_varname - - -### Externally supplied __usage. Nothing else to do here -############################################################################## - -if [[ "${__b3bp_external_usage:-}" = "true" ]]; then - unset -v __b3bp_external_usage - return -fi - - -### Signal trapping and backtracing -############################################################################## - -function __b3bp_cleanup_before_exit () { - info "Cleaning up. Done" -} -trap __b3bp_cleanup_before_exit EXIT - -# requires `set -o errtrace` -__b3bp_err_report() { - local error_code - error_code=${?} - error "Error in ${__file} in function ${1} on line ${2}" - exit ${error_code} -} -# Uncomment the following line for always providing an error backtrace -# trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR - - -### Command-line argument switches (like -d for debugmode, -h for showing helppage) -############################################################################## - -# debug mode -if [[ "${arg_d:?}" = "1" ]]; then - set -o xtrace - LOG_LEVEL="7" - # Enable error backtracing - trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR -fi - -# verbose mode -if [[ "${arg_v:?}" = "1" ]]; then - set -o verbose -fi - -# no color mode -if [[ "${arg_n:?}" = "1" ]]; then - NO_COLOR="true" -fi - -# help mode -if [[ "${arg_h:?}" = "1" ]]; then - # Help exists with code 1 - help "Help using ${0}" -fi - - -### Validation. Error out if the things required for your script are not present -############################################################################## - -[[ "${arg_f:-}" ]] || help "Setting a filename with -f or --file is required" -[[ "${LOG_LEVEL:-}" ]] || emergency "Cannot continue without LOG_LEVEL. " - - -### Runtime -############################################################################## - -info "__i_am_main_script: ${__i_am_main_script}" -info "__file: ${__file}" -info "__dir: ${__dir}" -info "__base: ${__base}" -info "OSTYPE: ${OSTYPE}" - -info "arg_f: ${arg_f}" -info "arg_d: ${arg_d}" -info "arg_v: ${arg_v}" -info "arg_h: ${arg_h}" - -info "$(echo -e "multiple lines example - line #1\nmultiple lines example - line #2\nimagine logging the output of 'ls -al /path/'")" - -# All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software -debug "Info useful to developers for debugging the application, not useful during operations." -info "Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required." -notice "Events that are unusual but not error conditions - might be summarized in an email to developers or admins to spot potential problems - no immediate action required." -warning "Warning messages, not an error, but indication that an error will occur if action is not taken, e.g. file system 85% full - each item must be resolved within a given time. This is a debug message" -error "Non-urgent failures, these should be relayed to developers or admins; each item must be resolved within a given time." -critical "Should be corrected immediately, but indicates failure in a primary system, an example is a loss of a backup ISP connection." -alert "Should be corrected immediately, therefore notify staff who can fix the problem. An example would be the loss of a primary ISP connection." -emergency "A \"panic\" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call." diff --git a/javascript_typescript/logging.js b/javascript_typescript/logging.js deleted file mode 100644 index 24ff1f4..0000000 --- a/javascript_typescript/logging.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -Author: T31M -2019 -*/ - -const { createLogger, format, transports } = require('winston'); - -const { combine, timestamp, printf, colorize, splat, json } = format; - -const maxFunctionLogLength = 60; - -const myFormat = printf(({ timestamp, loc, level, message }) => { - const start = process.hrtime(); - if (loc) { - return `${timestamp} ${level}: ${message - .toString() - .padEnd(105 - level.length)} ${loc.padEnd(60)} log: ${( - process.hrtime(start)[1] / 1000000 - ).toFixed(2)}ms`; - } - return `${timestamp} ${level}: ${message.padEnd(165 - level.length)} log: ${( - process.hrtime(start)[1] / 1000000 - ).toFixed(2)}ms`; -}); - -const preProcessing = format((info, opts) => { - const stack = new Error().stack.split('\n'); - stack.shift(); - for (elem of Object.values(stack)) { - elem = elem.toString().trim(); - if ( - elem.indexOf('node_modules') < 0 && - elem.indexOf('utils') < 0 - ) { - info.loc = elem.slice(3, elem.length); - if (info.loc.length > maxFunctionLogLength) { - info.loc = `${info.loc.slice( - 0, - info.loc.indexOf(' '), - )} -> ${info.loc.slice( - info.loc.lastIndexOf('\\') + 1, - info.loc.length - 1, - )}`; - } - return info; - } - } - return info; -}); - -module.exports.logger = createLogger({ - level: 'debug', - format: combine( - colorize(), - timestamp(), - // splat(), - preProcessing(), - myFormat, - // json(), - ), - // defaultMeta: { service: 'user-service' }, - transports: [ - // - // - Write to all logs with level `info` and below to `combined.log` - // - Write all logs error (and below) to `error.log`. - // - // new winston.transports.File({ filename: 'error.log', level: 'error' }), - // new winston.transports.File({ filename: 'combined.log' }) - new transports.Console({ format: format.myFormat }), - ], -}); \ No newline at end of file diff --git a/shell/dot.config/fish/config.fish b/shell/dot.config/fish/config.fish deleted file mode 100644 index ced1ae1..0000000 --- a/shell/dot.config/fish/config.fish +++ /dev/null @@ -1,2 +0,0 @@ -set -g -x fish_greeting 'Welcome to FiSH' -set -gx PATH ~/bin $PATH diff --git a/shell/dot.config/fish/fishfile b/shell/dot.config/fish/fishfile deleted file mode 100644 index d55d87e..0000000 --- a/shell/dot.config/fish/fishfile +++ /dev/null @@ -1,5 +0,0 @@ -oh-my-fish/theme-scorphish -umayr/theme-sushi -FabioAntunes/fish-nvm -edc/bass -jethrokuan/fzf diff --git a/shell/dot.config/fish/functions/fish_prompt.fish b/shell/dot.config/fish/functions/fish_prompt.fish deleted file mode 100644 index b0be085..0000000 --- a/shell/dot.config/fish/functions/fish_prompt.fish +++ /dev/null @@ -1,70 +0,0 @@ -function fish_prompt - set -l symbol "λ" - set -l code $status - - if test -n "$ssh_client" - set -l host (hostname -s) - set -l who (whoami) - echo -n -s (red)"("(cyan)"$who"(red)":"(cyan)"$host"(red)") "(off) - end - - if git::is_repo - set -l branch (git::branch_name ^/dev/null) - set -l ref (git show-ref --head --abbrev | awk '{print substr($0,0,7)}' | sed -n 1p) - - if git::is_stashed - echo -n -s (white)"^"(off) - end - - echo -n -s (red)"("(off) - - if git::is_dirty - printf (white)"*"(off) - end - - if command git symbolic-ref HEAD > /dev/null ^/dev/null - if git::is_staged - printf (cyan)"$branch"(off) - else - printf (yellow)"$branch"(off) - end - else - printf (dim)"$ref"(off) - end - - for remote in (git remote) - set -l behind_count (echo (command git rev-list $branch..$remote/$branch ^/dev/null | wc -l | tr -d " ")) - set -l ahead_count (echo (command git rev-list $remote/$branch..$branch ^/dev/null | wc -l | tr -d " ")) - - if test $ahead_count -ne 0; or test $behind_count -ne 0; and test (git remote | wc -l) -gt 1 - echo -n -s " "(orange)$remote(off) - end - - if test $ahead_count -ne 0 - echo -n -s (white)" +"$ahead_count(off) - end - - if test $behind_count -ne 0 - echo -n -s (white)" -"$behind_count(off) - end - end - - echo -n -s (red)") "(off) - end - - if test -n "$AWS_PROFILE" - set awsenv "[aws=$AWS_PROFILE]" - else - #set awsenv "[default]" #(aws profile) - set awsenv "" #(aws profile) - end - - if test "$code" = 0 - echo -n -s (red)"$symbol"(black)"$awsenv "(off) - #echo -n -s (red)"("(cyan)"$who"(red)":"(cyan)"$host"(red)") "(off) - else - echo -n -s (dim)"$symbol "(off) - - end - -end diff --git a/shell/dot.config/fish/functions/fish_right_prompt.fish b/shell/dot.config/fish/functions/fish_right_prompt.fish deleted file mode 100644 index e696a7d..0000000 --- a/shell/dot.config/fish/functions/fish_right_prompt.fish +++ /dev/null @@ -1,142 +0,0 @@ -# Colors -function orange - set_color -o ee5819 -end - -function yellow - set_color -o b58900 -end - -function red - set_color -o d30102 -end - -function cyan - set_color -o 2aa198 -end - -function white - set_color -o fdf6e3 -end - -function dim - set_color -o 4f4f4f -end - -function black - set_color -o 000000 -end - -function off - set_color -o normal -end - -# Git -function git::is_repo - test -d .git; or command git rev-parse --git-dir >/dev/null ^/dev/null -end - -function git::ahead -a ahead behind diverged none - not git::is_repo; and return - - set -l commit_count (command git rev-list --count --left-right "@{upstream}...HEAD" ^/dev/null) - - switch "$commit_count" - case "" - # no upstream - case "0"\t"0" - test -n "$none"; and echo "$none"; or echo "" - case "*"\t"0" - test -n "$behind"; and echo "$behind"; or echo "-" - case "0"\t"*" - test -n "$ahead"; and echo "$ahead"; or echo "+" - case "*" - test -n "$diverged"; and echo "$diverged"; or echo "±" - end -end - -function git::branch_name - git::is_repo; and begin - command git symbolic-ref --short HEAD ^/dev/null; - or command git show-ref --head -s --abbrev | head -n1 ^/dev/null - end -end - -function git::is_dirty - git::is_repo; and not command git diff --no-ext-diff --quiet --exit-code -end - -function git::is_staged - git::is_repo; and begin - not command git diff --cached --no-ext-diff --quiet --exit-code - end -end - -function git::is_stashed - git::is_repo; and begin - command git rev-parse --verify --quiet refs/stash >/dev/null - end -end - -function git::is_touched - git::is_repo; and begin - test -n (echo (command git status --porcelain)) - end -end - -function git::untracked - git::is_repo; and begin - command git ls-files --other --exclude-standard - end -end - -# Kubernetes - -function k8s::current_context - command kubectl config current-context -end - -function k8s::current_namespace - command kubectl config view --minify -o jsonpath='{.contexts[0].context.namespace}' -end - -# Terraform - -# Test whether this is a terraform directory by finding .tf files -function terraform::directory - command find . -name '*.tf' >/dev/null ^/dev/null -maxdepth 0 -end - -function terraform::workspace - terraform::directory; and begin - test -e .terraform/environment - end -end - -function fish_right_prompt - - if test "$theme_complete_path" = "yes" - set cwd (prompt_pwd) - else - set cwd (basename (prompt_pwd)) - - if git::is_repo - set root_folder (command git rev-parse --show-toplevel ^/dev/null) - set parent_root_folder (dirname $root_folder) - set cwd (echo $PWD | sed -e "s|$parent_root_folder/||") - end - end - - command -sq kubectl; and k8s::current_context 2>/dev/null; and begin - printf (yellow)"("(dim)(k8s::current_context)"/"(k8s::current_namespace)(yellow)") "(off) - end - - if terraform::workspace - set terraform_workspace_name (command cat .terraform/environment) - printf (yellow)"("(dim)$terraform_workspace_name(yellow)") "(off) - end - - printf (yellow)"("(dim)$cwd(yellow)") "(off) - printf (dim)(date +%H(yellow):(dim)%M(yellow):(dim)%S)(off) - -end diff --git a/shell/dot.vimrc b/shell/dot.vimrc deleted file mode 100644 index 2bdecde..0000000 --- a/shell/dot.vimrc +++ /dev/null @@ -1,15 +0,0 @@ -:set mouse=r -:color desert -:syntax on -:set nu -:set list -:set listchars=tab:>- - -:filetype plugin indent on -" show existing tab with 4 spaces width -:set tabstop=4 -" when indenting with '>', use 4 spaces width -:set shiftwidth=4 -" On pressing tab, insert 4 spaces -:set expandtab - diff --git a/shell/fish_setup.sh b/shell/fish_setup.sh deleted file mode 100644 index d637550..0000000 --- a/shell/fish_setup.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# install fisher -curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish - -# install sushi-theme -fisher add https://github.com/umayr/theme-sushi - -# install bass -fisher add edc/bass - -# install fzf bin -sudo apt install fzf - -# install fzf -fisher add jethrokuan/fzf - -# customize theme / prompt