Skip to content

Commit

Permalink
Merge branch 'python' of github.com:jeff-hykin/fornix
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-hykin committed Oct 14, 2022
2 parents 59c5fab + 04f28ee commit 65a8eec
Show file tree
Hide file tree
Showing 33 changed files with 1,315 additions and 400 deletions.
7 changes: 4 additions & 3 deletions commands/shell
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p bash_5 -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/7e9b0dff974c89e070da1ad85713ff3c20b0ca97.tar.gz
#! nix-shell -i bash -p bash_5 -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/ce6aa13369b667ac2542593170993504932eb836.tar.gz

# the comments above^ are special
# they tell the system to process this using nix-shell
Expand Down Expand Up @@ -79,14 +79,15 @@ if [ "$FORNIX_DEBUG" = "true" ]; then
echo "switching from Bash to Zsh"
echo "changing HOME to temp folder for nix-shell"
fi
export TMPDIR="/tmp" # fixes some build problems (workaround for a bug in Nix)
__temp_var__nix_shell_file="$FORNIX_FOLDER/settings/extensions/nix/shell.nix"
if [[ -n "$FORNIX_ARGS" ]]
then
# FIXME: I think the single quotes need to be escaped from the arguments (need to iterate over them, escape each one with single quotes)
# run single command
HOME="$FORNIX_HOME" nix-shell --pure --run "zsh -c '$FORNIX_ARGS'" "$__temp_var__nix_shell_file"
HOME="$FORNIX_HOME" nix-shell --pure --show-trace --run "zsh -c '$FORNIX_ARGS'" "$__temp_var__nix_shell_file" -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/a7ecde854aee5c4c7cd6177f54a99d2c1ff28a31.tar.gz --keep __FORNIX_NIX_SETTINGS_PATH --keep __FORNIX_NIX_MAIN_CODE_PATH --keep __FORNIX_NIX_PACKAGES_FILE_PATH --keep __FORNIX_NIX_PATH_EXPORT_FILE --keep __FORNIX_NIX_COMMANDS --keep FORNIX_FOLDER
else
HOME="$FORNIX_HOME" nix-shell --pure --command "zsh" "$__temp_var__nix_shell_file"
HOME="$FORNIX_HOME" nix-shell --pure --show-trace --command "zsh" "$__temp_var__nix_shell_file" -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/a7ecde854aee5c4c7cd6177f54a99d2c1ff28a31.tar.gz --keep __FORNIX_NIX_SETTINGS_PATH --keep __FORNIX_NIX_MAIN_CODE_PATH --keep __FORNIX_NIX_PACKAGES_FILE_PATH --keep __FORNIX_NIX_PATH_EXPORT_FILE --keep __FORNIX_NIX_COMMANDS --keep FORNIX_FOLDER
fi
if [ "$FORNIX_DEBUG" = "true" ]; then
echo "exited the nix-shell environment"
Expand Down
155 changes: 155 additions & 0 deletions commands/start
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# summary
#
# find fornix, make sure nix exists
# with no arguments, this simply starts the shell
# with an argument, it refreshes the project connections, then runs `$commands_folder/project/$the_arguments`

Expand Down Expand Up @@ -45,6 +46,160 @@ export FORNIX_NEXT_RUN_DONT_DO_MANUAL_START="true"
if [ "$FORNIX_DEBUG" = "true" ]; then
echo "starting: $FORNIX_COMMANDS_FOLDER"start
fi

#
# fix the windows WSL mkfifo problem
#
if [ -d "/mnt/c" ]
then
# create some helpers
move_out_of_the_way () {
if [[ -e "$1" ]]
then
# if something is in the way, move it out of the way
# (recursively)
if [[ -e "$1.old" ]]
then
move_out_of_the_way "$1.old"
fi

# now that anything that would be in the way has been moved
mv "$1" "$1.old"
fi
}
prev_command_successful () {
return $?
}

#
# check for mounting with metadata
#

# if project is inside the windows C drive
if [[ "$FORNIX_FOLDER" == "/mnt/c"* ]]; then
echo '__________________________________________________________________________________'
echo '| |'
echo '| Howdy! |'
echo '| |'
echo '| Looks like your project is saved in the windows file system |'
echo '| (instead of the Linux/WSL file system) |'
echo '| |'
echo '| This is a bit of a problem since the file systems of |'
echo '| Linux/Mac/Android/ChromeBook/OpenBSD/etc have many features |'
echo '| that the windows file system does not have. |'
echo '| |'
echo '| Would it be okay if I move this project? |'
echo '| I`ll create a shortcut to it so you can still find it. |'
echo '| https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/ |'
echo '| |'
echo '----------------------------------------------------------------------------------'
echo
question="[y/n]: ";answer=''
while true; do
echo "$question"; read response
case "$response" in
[Yy]* ) answer='yes'; break;;
[Nn]* ) answer='no'; break;;
* ) echo "Please answer yes or no.";;
esac
done
if [ "$answer" = 'no' ]; then
echo '
okay, in that case just re-run this command whenever
you have moved the project to the linux file system
if you`re confused about what that^ means
take a look at the "fornix_framework.md" file inside
of the "documentation" folder (inside of this project folder)
'
exit
else
#
# where to move project
#
new_project_location="$HOME/repos/$(basename "$FORNIX_FOLDER")"
while true; do
question="Is it okay if I move the project to '$new_project_location'? [y/n]";answer=''
while true; do
echo "$question"; read response
case "$response" in
[Yy]* ) answer='yes'; break;;
[Nn]* ) answer='no'; break;;
* ) echo "Please answer yes or no.";;
esac
done
if [ "$answer" = 'no' ]; then
echo ""
echo "Where would you like to put it?"
echo "(press enter when done typing the path):"
echo ""
read new_project_location
else
break
fi
done

#
# move the project
#

# if something is in the way, move it out of the way
if [ -e "$new_project_location" ]
then
move_out_of_the_way "$new_project_location"
fi

# make sure the parent folder exists
mkdir -p "$(dirname "$new_project_location")"

# move the project itself
prev_command_successful && mv "$FORNIX_FOLDER" "$new_project_location"

# create a shortcut to the project
prev_command_successful && ln -s "$new_project_location" "$FORNIX_FOLDER"

# cd and start the project
prev_command_successful && cd "$new_project_location" && "$new_project_location/commands/start"
# note: commands/start is needed in the above command so the FORNIX_FOLDER and other checks/setup can be redone
# so just exit right after because this script has become just a wrapper at this point
exit $?
fi
fi

# check if metadata enabled already
if ! mount -l | grep 'C: on /mnt/c' | grep 'metadata' &>/dev/null
then
echo '__________________________________________________________________________________'
echo '| |'
echo '| Howdy! |'
echo '| |'
echo '| Looks like there`s a metadata hiccup/problem. It seems you`re using WSL |'
echo '| Sadly, for some reason, WSL doesn`t (by default) support many features of the |'
echo '| linux file system. And For some reason, adding that support requires |'
echo '| re-mounting the C drive (within WSL) with metadata enabled. |'
echo '| |'
echo '| I`ll run the command automatically, but if you don`t want to put |'
echo '| your password in, cancel this (CTRL+C) and run the following yourself: |'
echo '| |'
echo ' cd ; sudo umount /mnt/c && sudo mount -t drvfs C: /mnt/c -o metadata; cd - '
echo '| |'
echo '| Then re-run this script |'
echo '| You can read more about this problem here if you like: |'
echo '| https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/ |'
echo '| |'
echo '----------------------------------------------------------------------------------'
echo
echo "Continue?"; read _
pwd_before="$PWD"
# this means we need to unmount and remount with metadata enabled
cd && sudo umount /mnt/c && sudo mount -t drvfs C: /mnt/c -o metadata
cd "$pwd_before"
fi
fi

. "$FORNIX_FOLDER/settings/extensions/nix/commands/ensure_nix_installed"

# just start the shell with no arguments (arguments might be supported in the future)
"$FORNIX_COMMANDS_FOLDER/shell"
if [ "$FORNIX_DEBUG" = "true" ]; then
Expand Down
11 changes: 11 additions & 0 deletions commands/subrepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env -S deno run --allow-all
import { FileSystem } from "https://deno.land/x/[email protected]/main/file_system.js"
import { run, Stderr, Stdout } from "https://deno.land/x/[email protected]/main/run.js"

// go to project root
FileSystem.cwd = await FileSystem.walkUpUntil(".git/")

await run`git add -A`
await run`git commit -m -`
const { exitCode } = await run("git", "subrepo", ...Deno.args)
Deno.exit(exitCode)
13 changes: 7 additions & 6 deletions documentation/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Install:
### If you're an Experienced/Senior Dev

- (Don't git clone)
- Run this: `repo=https://github.com/jeff-hykin/berkeley_pacman eval "$(curl -fsSL git.io/JE2Zm || wget -qO- git.io/JE2Zm)"`
- Run this: `repo=https://github.com/jeff-hykin/berkeley_pacman setup_or_copy=setup branch=master eval "$(curl -fsSL git.io/JE2Zm || wget -qO- git.io/JE2Zm)"`
- If you're on Windows, run it inside WSL (Ubuntu 20.04 preferably)
- If you're a responsible human being and therefore don't want run a sketchy internet script, props to you 👍. Take a look at the explaination below and you'll be able to run the commands yourself.
- If you're a responsible human being and therefore don't want run a sketchy internet script, props to you 👍. Take a look at the "What is that `eval` command doing?" section at the bottom and you'll be able to run the commands yourself.

### If the above instructions didn't make sense

Expand All @@ -31,7 +31,7 @@ Install:
- Windows users
- Normally you just install [WSL](https://youtu.be/av0UQy6g2FA?t=91) and follow the Linux instructions, however the project uses a GUI and WSL doesn't like GUI's. <br>So there are a few options:
1. You might just want to try manually installing everything (manual install details at the top)
2. (Recommended) Install [virtualbox](https://www.virtualbox.org/wiki/Downloads) and setup Ubuntu 18.04 or Ubuntu 20.04
2. (Recommended) Install [virtualbox](https://www.virtualbox.org/wiki/Downloads) and setup Ubuntu 20.04 or Ubuntu 22.04
- Here's [a 10 min tutorial](https://youtu.be/QbmRXJJKsvs?t=62) showing all the steps
- Once its installed, boot up the Ubuntu machine, open the terminal/console app and follow the Linux instructions
3. Get WSL2 with Ubuntu, and use Xming
Expand All @@ -42,15 +42,16 @@ Install:
- [Xming link](https://sourceforge.net/projects/xming/?source=typ_redirect)
- Once you have a WSL/Ubuntu terminal setup, follow the Linux instructions


After you've finished working and close the terminal, you can always return to project environment by doing
- `cd wherever-you-put-the-project`
- `cd WHEREVER_YOU_PUT_THE_PROJECT`
- `commands/start`


### What is that `eval` command doing?

1. Installing nix [manual install instructions here](https://nixos.org/guides/install-nix.html)
1. Installing nix [manual install instructions here](https://nixos.org/download.html)
2. Installing `git` (using nix) if you don't already have git
3. It clones the repository
4. It `cd`'s inside of the repo
5. Then it runs `commands/start` to enter the project environment
5. Then it runs `commands/start` to enter the project environment
5 changes: 0 additions & 5 deletions settings/during_start/001_000__setup_zsh__.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR="$zsh_syntax_highlighting__path/share/zsh-
. "$zsh_auto_suggest__path/share/zsh-autosuggestions/zsh-autosuggestions.zsh"

SPACESHIP_CHAR_SYMBOL="" # ☣ ⁂ ⌘ ∴ ∮ ֎ Ͽ ♫ ⛬ ⚿ ♦ ♢ ⛶ ✾ ❒ ⟩ ⟡ ⟜ ⟦ ⦊ ⦒ ⪢ ⪾ ∫ ∬ ∭
SPACESHIP_VENV_SYMBOL="🐍$(python -V 2>&1 | sed -E 's/Python//g' )"
SPACESHIP_VENV_PREFIX=""
SPACESHIP_VENV_GENERIC_NAMES="."
SPACESHIP_VENV_COLOR="green"
SPACESHIP_NODE_COLOR="yellow"

# Set Spaceship ZSH as a prompt
autoload -U promptinit; promptinit
Expand Down
4 changes: 4 additions & 0 deletions settings/during_start/001_010__setup_nix_path__.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#
# import paths from nix
#
export NIX_PATH="$HOME/.nix-defexpr/channels"
68 changes: 61 additions & 7 deletions settings/during_start/094_000_jeffs_git_shortcuts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ git_checkout () {
git switch "$@"
return
}
printf '%s' "$__temp_var__branches" | grep "$2" 2>/dev/null 1>/dev/null && {
# if second arg exists
if [ -n "$2" ]
then
printf '%s' "$__temp_var__branches" | grep "$2" 2>/dev/null 1>/dev/null && {
unset __temp_var__branches
git switch "$@"
return
}
unset __temp_var__branches
git switch "$@"
return
}
unset __temp_var__branches
fi
#
# otherwise use checkout
#
Expand All @@ -29,14 +33,34 @@ git_commit_hashes () {
}

git_log () {
git log --oneline
git log --first-parent --date=short --pretty=format:"%Cblue%ad %h%Cgreen %s %Creset%d"
}

git_current_commit_hash () {
# https://stackoverflow.com/questions/949314/how-to-retrieve-the-hash-for-the-current-commit-in-git
git rev-parse HEAD
}

git_oldest_commit_hash () {
git log --reverse --oneline | head -n1 | sed -e 's/ .*//'
}

git_squash_all () {
git reset --soft $(git_oldest_commit_hash)
}

git_squash_to () {
commit_hash="$1"
commit_message="$2"
git reset --soft "$commit_hash" && git add -A && git commit -m "$commit_message" && echo "squash complete"
}

git_squash () {
args="$@"
git reset --soft HEAD~2 && git add -A && git commit -m "$args" && echo "squash complete"
git_log | head -n5
}

#
# sync
#
Expand Down Expand Up @@ -94,6 +118,34 @@ git_keep_theirs () { # git keep theirs
git commit -m "_Accepting all incoming changes $@"
}

git_add_upstream () {
remote_name="$1"
remote_url="$2"
if [ -z "$remote_name" ]
then
echo "what should the upstream source be called?"
read remote_name
fi
if [ -z "$remote_url" ]
then
echo "what is the url to the upstream source?"
read remote_url
fi

git remote add "$remote_name" "$remote_url"
}

git_change_origin () {
remote_url="$1"
if [ -z "$remote_url" ]
then
echo "what is the url to the upstream source?"
read remote_url
fi
# change origin
git remote set-url "origin" "$remote_url"
}

#
# Branch
#
Expand Down Expand Up @@ -406,5 +458,7 @@ alias gb="git branch -a"
alias gnb="git_new_branch"
alias gd="git_delete_changes"
alias gcp="git add -A;git stash"
alias gct="git add -A;git stash"
alias gpst="git stash pop;git add -A"
alias gundo="git reset --soft HEAD~1"
alias gundo="git reset --soft HEAD~1"
alias gurl="git_url_of_origin"
5 changes: 5 additions & 0 deletions settings/during_start/099_050_finish_spaceship_setup_.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SPACESHIP_VENV_SYMBOL="🐍$(python -V 2>&1 | sed -E 's/Python//g' )"
SPACESHIP_VENV_PREFIX=""
SPACESHIP_VENV_GENERIC_NAMES="."
SPACESHIP_VENV_COLOR="green"
SPACESHIP_NODE_COLOR="yellow"
Loading

0 comments on commit 65a8eec

Please sign in to comment.