Skip to content

Commit

Permalink
Various tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisroovers committed Aug 13, 2024
1 parent 378fc61 commit f332050
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 33 deletions.
109 changes: 83 additions & 26 deletions .aliases_functions.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
### PROGRAM OVERRIDES #################################################################################################
alias cat='bat' # https://github.com/sharkdp/bat
#alias find='fd' # https://github.com/sharkdp/fd
alias ls="lsd" # https://github.com/Peltoche/lsdexport
alias ssh="assh wrapper ssh --" # https://github.com/moul/assh

# Program aliases
alias excel="open -a 'Microsoft Excel'"
alias code="code-insiders"
alias vscode="code-insiders"
alias pc="pre-commit"

### SHELL UTILITIES ####################################################################################################
alias choose="fzf --height 10"
alias fchoose="ls | choose"
Expand All @@ -14,19 +26,14 @@ cenv(){
shift
fi

# Filter output (print all if nothing is passed)
if [ -n "$1" ]; then
output=$(env | grep -i $1 --color=always)
else
output=$(env)
fi
output=$(env)

# Redacting
if [ $redact_data -eq 1 ]; then
# Extract sensitive values
sensitive_values=()
for var in $(echo "$output" | grep -E "PASSWORD|TOKEN|SECRET|KEY|ROLE_ID" | cut -d '=' -f 2); do
escaped_val=$(echo "$var" | sed 's/[]\/$*.^[]/\\&/g')
for var in $(echo "$output" | grep -E "PASSWORD|TOKEN|SECRET|KEY|ROLE_ID" | cut -d '=' -f 2-); do
escaped_val=$(echo "$var" | sed 's/[]\/$*.^+[]/\\&/g')
sensitive_values+=($escaped_val)
done

Expand All @@ -36,17 +43,29 @@ cenv(){
done

# Mark empty variables and exclude PS1
echo "$output" | grep -ve "^PS1" | sed -E "s/([^=]+)=$/\1=<empty>/"
else
echo "$output"
output=$(echo "$output" | grep -ve "^PS1" | sed -E "s/([^=]+)=$/\1=<empty>/")
fi

# Filter output if a search string is passed
if [ -n "$1" ]; then
output=$(echo "$output" | grep -i $1 --color=always)
fi

echo "$output"
}

# Unset env vars based on regex matching (case insensitive)
unsetall(){
vars="$(env | grep -i $1 | awk -F "=" '{print $1}')"
unset $vars
echo "Unset: $vars"
# Get matching variable names as a newline-separated string
vars=$(env | grep -i "$1" | awk -F "=" '{print $1}')
# Convert newline-separated variable names to an array in a cross-shell compatible manner
if [[ -n "$vars" ]]; then
# Use a while loop to read each line
while IFS= read -r var; do
unset "$var"
echo "Unset: $var"
done <<< "$vars"
fi
}

# Edit an ENV VAR in $EDITOR, then export it back to the shell
Expand All @@ -61,10 +80,18 @@ editvar(){

# Select dotfile to source from .rc directory
sl(){
echo "Use alias 'se' to easily edit these files"
# find -L: follow symlinks
source $(find -L ~/.rc -type f | choose)
}

se(){
echo "Use alias 'se' to easily edit these files"
# find -L: follow symlinks
code $(find -L ~/.rc -type f | choose)
}


# Shows definition of passed alias or function
define(){
# type $1
Expand Down Expand Up @@ -227,18 +254,6 @@ focus-desk(){
echo "Terminal set to dark mode"
}

### PROGRAM OVERRIDES #################################################################################################
alias cat='bat' # https://github.com/sharkdp/bat
#alias find='fd' # https://github.com/sharkdp/fd
alias ls="lsd" # https://github.com/Peltoche/lsdexport
alias ssh="assh wrapper ssh --" # https://github.com/moul/assh

# Program aliases
alias excel="open -a 'Microsoft Excel'"
alias code="code-insiders"
alias vscode="code-insiders"
alias pc="pre-commit"

### DATA WRANGLING ####################################################################################################
# .utils.py is a python script that contains functions for data wrangling
# While some of these could be written as pure shell functions, python makes many functions simpler and portable across
Expand Down Expand Up @@ -376,6 +391,7 @@ function alias-docker(){
alias dnl='docker network list'

alias dc='docker-compose'
alias | grep docker
}


Expand Down Expand Up @@ -409,3 +425,44 @@ d42put(){
d42delete(){
curl -s -k -u "$D42_USERNAME:$D42_PASSWORD" -X DELETE "$D42_BASE_URL$@"
}


### Tableau ############################################################################################################


tableau_get(){
curl -s -H "X-Tableau-Auth: $TABLEAU_TOKEN" -H "Accept: application/json" "$TABLEAU_URL$@"
}

tableau_post(){
curl -s -X POST -H "X-Tableau-Auth: $TABLEAU_TOKEN" -H "Accept: application/json" "$TABLEAU_URL$@"
}

tableau_site_get(){
tableau_get "/sites/$TABLEAU_SITE_ID$@"
}

tableau_site_post(){
tableau_post "/sites/$TABLEAU_SITE_ID$@"
}

tableau_signin(){
PAYLOAD=$(cat <<EOF
{
"credentials": {
"personalAccessTokenName": "$TABLEAU_PERSONAL_ACCESS_TOKEN_NAME",
"personalAccessTokenSecret": "$TABLEAU_PERSONAL_ACCESS_TOKEN",
"site": {
"contentUrl": "$TABLEAU_CONTENTURL"
}
}
}
EOF
)

export TABLEAU_TOKEN=$(curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d "$PAYLOAD" $TABLEAU_URL/auth/signin | jq -r ".credentials.token")
cenv TABLEAU_TOKEN

export TABLEAU_SITE_ID=$(tableau_get "/sites" | jq -r ".sites.site[] | select(.contentUrl == \"$TABLEAU_CONTENTURL\").id")
cenv TABLEAU_SITE_ID
}
3 changes: 2 additions & 1 deletion .config/gh/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ aliases:
co: pr checkout
# See https://github.com/cli/cli/issues/846#issuecomment-1142104190
prl: pr list --json number,title,headRefName,author --template '{{range .}}{{tablerow (printf "#%v" .number | autocolor "green") .title (.headRefName | color "cyan") (.author.login | color "yellow") }}{{end}}'
prc: "!gh pr checkout $(gh prl | fzf --height 10 | cut -f1 -d ' ' | sd '#' '')"
prc: "!gh pr checkout $(gh prl | fzf --height 10 | cut -f1 -d ' ' | sd '#' '')"
version: "1"
3 changes: 3 additions & 0 deletions .env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export PYTHONSTARTUP="$HOME/.pythonrc.py"

### MISC ###############################################################################################################

# Bat's default theme on MacOS is hard to read in iTerm2
export BAT_THEME=1337

export PGM_KEY_FILE=~/keys/pgm.pem

# Adds colors to grep on mac
Expand Down
7 changes: 5 additions & 2 deletions .gitconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
# Don't require `--set-upsttram origin` when pushing branches
autoSetupRemote = true

[init]
# Set default branch to 'main' when creating a new repository
defaultBranch = main

[interactive]
diffFilter = delta --color-only

Expand All @@ -44,8 +48,7 @@

[includeIf "gitdir:~/workspaces/"]
path = ~/.gitconfig_work
[init]
defaultBranch = main

[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
Expand Down
4 changes: 2 additions & 2 deletions .version-managers.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RTX (https://github.com/jdxcode/rtx)
[[ -s "$(brew --prefix rtx)/bin/rtx" ]] && eval "$($(brew --prefix rtx)/bin/rtx activate $SHELL_NAME)"
# mise (https://github.com/jdxcode/mise)
[[ -s "$(brew --prefix mise)/bin/mise" ]] && eval "$($(brew --prefix mise)/bin/mise activate $SHELL_NAME)"

# ASDF (version manager to rule them all!): https://asdf-vm.com/
# [[ -s "$(brew --prefix asdf)/libexec/asdf.sh" ]] && source "$(brew --prefix asdf)/libexec/asdf.sh"
Expand Down
2 changes: 1 addition & 1 deletion Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cask "1password-cli"
tap "homebrew/cask-fonts"
cask "font-hack-nerd-font"

# TODO: convert to install command(s)
brew "hashicorp/tap/vault"

# Cleaned output of `brew list --full-name -1`
# List with libraries removed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,10 @@
"oracledb",
"piechart",
"sqlalchemy"
]
],
"github.copilot.editor.enableAutoCompletions": true,
"[scss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"git.openRepositoryInParentFolders": "never"
}

0 comments on commit f332050

Please sign in to comment.