-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shells: Revamp aliases and ENV system
- Use Python for parsing `addpath` file - Move the script to ~/dotscripts - Support Nu for aliases - Add notes on installing Nu and setting up bash - Update setup script for fish
- Loading branch information
Showing
11 changed files
with
144 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
# In addition to this file being valid POSIX, all RHS of `=` must use single | ||
# quotes, and must be convertible to nu and fish (also see ~/dotscripts/gen/nu | ||
# and check ~/.aliases.nu) | ||
|
||
# Program aliases | ||
alias x=exit | ||
alias clr=clear | ||
alias y=yadm | ||
alias td=termdown | ||
alias hdi=howdoi | ||
alias bom=bombadillo | ||
alias syscu='systemctl --user' | ||
alias edoom='emacs --with-profile=doom' | ||
alias g=git | ||
alias acme='acme -f /mnt/font/FiraCode-Regular/15/font' | ||
alias la='ls -Ah' | ||
alias la='ls -a' | ||
|
||
# Shortcuts | ||
alias apt-up='sudo apt update && sudo apt upgrade -y && sudo apt-get dist-upgrade -y && sudo apt autoremove' | ||
alias newvenv='python3 -m virtualenv venv && source ./venv/bin/activate.fish' | ||
alias localusrlocal='rsync ~/local/usr/local/ ~/local/ -avr && rm -rf ~/local/usr/local' | ||
alias localusr='rsync ~/local/usr/ ~/local/ -avr && rm -rf ~/local/usr' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python3 | ||
# read addpath file and return each path | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
home = str(Path.home()) | ||
added = {} | ||
|
||
def getpaths(file: str): | ||
global added | ||
addpaths = Path(file) | ||
if not addpaths.exists(): | ||
return | ||
|
||
lines = addpaths.read_text(encoding="utf-8").splitlines() | ||
for line in lines: | ||
path = line.strip() | ||
if not path: | ||
continue | ||
if path.startswith("#"): | ||
continue | ||
if not path.startswith("/"): | ||
path = f"{home}/{path}" | ||
if not added.get(path, False): | ||
added[path] = True | ||
yield path | ||
|
||
|
||
sep = ":" | ||
if len(sys.argv) > 1: | ||
sep = sys.argv[1] | ||
|
||
###### | ||
file = f"{home}/.addpath" | ||
print( | ||
f"{home}/bin", | ||
f"{home}/local/bin", | ||
*getpaths(file), | ||
*getpaths(file+"_local"), | ||
sep=sep | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
# Stubbornly translates ~/.exportenvs to ~/.exportenvs.fish | ||
|
||
input=~/.exportenvs | ||
output="$input.fish" | ||
|
||
# clear the file | ||
rm $output | ||
touch $output | ||
|
||
while read fileline; do | ||
line=$(echo "$fileline" | sed 's/#.*//' | sed 's/export //') | ||
if [ -z "$line" ]; then | ||
continue | ||
fi | ||
tline=$(echo "$line" | sed 's/=/ /') | ||
echo "set -x $tline" >> $output | ||
done < $input |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env nu | ||
|
||
# Aliases | ||
let file = $"($env.HOME)/.aliases.nu" | ||
if ($"($env.HOME)/.aliases" | path exists) { | ||
'' | save -f $file | ||
for $line in (cat ~/.aliases | lines) { | ||
if ($line | str starts-with "alias") { | ||
let parts = ($line | str substring 6.. | split row '=' ) | ||
let name = $parts.0 | ||
mut cmd = ($parts.1 | str replace -a "'" '' | str replace -a " && " "; ") | ||
mut stmt = "" | ||
if ($cmd | str contains "; ") { | ||
# RHS of alias command must be a valid command. If there are | ||
# more commands, use a def instead. | ||
if ($cmd | split words | $in.0) == $name { | ||
$cmd = $"^($cmd)" | ||
} | ||
$stmt = $" | ||
# Alias of '($cmd)' | ||
def --env ($name) [] { | ||
($cmd) | ||
}" | ||
} else { | ||
$stmt = $"alias ($name) = ($cmd)" | ||
} | ||
$"($stmt)\n" | save -a $file | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo https://www.nushell.sh/book/installation.html | ||
echo | ||
echo ' | ||
sudo cat <<END | ||
#!/bin/sh | ||
XDG_CONFIG_HOME=~/.config /opt/homebrew/bin/nu "$@" | ||
END > /usr/local/bin/nu | ||
sudo chmod +x /usr/local/bin/nu | ||
' | ||
|
||
echo add it to /etc/shells |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo Ensure .startup.sh is sourced, and make sure it is only sourced ONCE | ||
echo '(Otherwise $PATH precedence will be messed up)' | ||
echo | ||
echo Run these yourself: | ||
echo | ||
echo sudo echo "'"'[ -r "$HOME/.startup.sh" ] && . "$HOME/.startup.sh"'"'" '| tee -a /etc/profile >> /etc/bashrc' | ||
echo 'cat <<END | ||
if ! grep "startup.sh" /etc/bashrc > /dev/null; then | ||
source ~/.startup.sh | ||
fi | ||
END | tee -a ~/.profile >> ~/.bashrc' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env nu | ||
|
||
print "Re-generating config files" | ||
~/dotscripts/gen/nu | ||
|
||
print "Please reload the shell" |