Devenv config
This commit is contained in:
@@ -1046,7 +1046,40 @@ any directory proffered by `consult-dir'."
|
|||||||
(eshell/cd (substring-no-properties
|
(eshell/cd (substring-no-properties
|
||||||
(consult-dir--pick "Switch directory: ")))))
|
(consult-dir--pick "Switch directory: ")))))
|
||||||
(t (eshell/cd (if regexp (eshell-find-previous-directory regexp)
|
(t (eshell/cd (if regexp (eshell-find-previous-directory regexp)
|
||||||
(completing-read "cd: " eshell-dirs))))))))
|
(completing-read "cd: " eshell-dirs)))))))
|
||||||
|
|
||||||
|
(defun eshell/mkenv (&rest args)
|
||||||
|
"Initialize a devenv environment or configure its .envrc.
|
||||||
|
|
||||||
|
With optional argument --here or -h, forces execution in the
|
||||||
|
current directory instead of the project root."
|
||||||
|
(interactive)
|
||||||
|
(let* ((here-flag (or (member "--here" args) (member "-h" args)))
|
||||||
|
(project-root
|
||||||
|
;; Use Projectile to find the root if available, otherwise fallback to git.
|
||||||
|
(cond
|
||||||
|
((fboundp 'project-root) (project-root (project-current)))
|
||||||
|
((shell-command-to-string "git rev-parse --is-inside-work-tree")
|
||||||
|
(string-trim (shell-command-to-string "git rev-parse --show-toplevel")))))
|
||||||
|
(target-dir
|
||||||
|
(if (or here-flag (not project-root))
|
||||||
|
default-directory
|
||||||
|
project-root))
|
||||||
|
;; Localize all file operations to the target directory
|
||||||
|
(default-directory target-dir))
|
||||||
|
|
||||||
|
(if (not (file-exists-p "devenv.nix"))
|
||||||
|
;; If it doesn't exist, we assume this is a new project.
|
||||||
|
(call-process "devenv" nil 0 nil "init"))
|
||||||
|
|
||||||
|
(when (not (file-exists-p ".envrc"))
|
||||||
|
;; If .envrc is missing, create and configure it for devenv.
|
||||||
|
(with-temp-file ".envrc"
|
||||||
|
(insert "eval \"$(devenv direnvrc)\"")))
|
||||||
|
|
||||||
|
(if (file-exists-p "devenv.nix")
|
||||||
|
(find-file (expand-file-name "devenv.nix" target-dir))
|
||||||
|
(message "Could not open devenv.nix as it was not created.")))))
|
||||||
|
|
||||||
(use-package eshell
|
(use-package eshell
|
||||||
:bind (:map eshell-hist-mode-map
|
:bind (:map eshell-hist-mode-map
|
||||||
|
|||||||
@@ -18,4 +18,11 @@ compile_commands.json
|
|||||||
.ipynb_checkpoints
|
.ipynb_checkpoints
|
||||||
infer-out
|
infer-out
|
||||||
.cache
|
.cache
|
||||||
.aider*
|
.aider*
|
||||||
|
|
||||||
|
# Devenv
|
||||||
|
.devenv*
|
||||||
|
devenv.local.nix
|
||||||
|
|
||||||
|
# pre-commit
|
||||||
|
.pre-commit-config.yaml
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
aider-chat
|
aider-chat
|
||||||
sops
|
sops
|
||||||
just
|
just
|
||||||
|
devenv
|
||||||
];
|
];
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ let tide_conf = builtins.readFile ./tide_config.fish; in
|
|||||||
|
|
||||||
shellInit = ''
|
shellInit = ''
|
||||||
set --universal fish_greeting
|
set --universal fish_greeting
|
||||||
set -g -x EDITOR "vim"
|
set -g -x EDITOR "emacsclient -a \"emacs -nw\""
|
||||||
set -g -x ALTERNATE_EDITOR "vim"
|
set -g -x ALTERNATE_EDITOR "vim"
|
||||||
set -g -x TERMINAL "kitty"
|
set -g -x TERMINAL "kitty"
|
||||||
set -g -x LESS "--ignore-case --QUIET --RAW-CONTROL-CHARS"
|
set -g -x LESS "--ignore-case --QUIET --RAW-CONTROL-CHARS"
|
||||||
@@ -61,6 +61,40 @@ let tide_conf = builtins.readFile ./tide_config.fish; in
|
|||||||
command ssh $argv
|
command ssh $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mkenv --description "Initialize a devenv environment or configure its .envrc"
|
||||||
|
argparse --name=mkenv h/here -- $argv
|
||||||
|
or return 1 # Exit if parsing fails
|
||||||
|
|
||||||
|
# Default target directory is the current directory.
|
||||||
|
set -l target_dir "."
|
||||||
|
|
||||||
|
# Check if we are inside a Git repository's working tree.
|
||||||
|
if git rev-parse --is-inside-work-tree >/dev/null 2>&1
|
||||||
|
if not set -q _flag_here; and not test -f devenv.nix
|
||||||
|
set target_dir (git rev-parse --show-toplevel)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
pushd "$target_dir"
|
||||||
|
|
||||||
|
# Check for the existence of the primary devenv configuration file.
|
||||||
|
if not test -f "devenv.nix"
|
||||||
|
devenv init
|
||||||
|
else
|
||||||
|
# If devenv.nix exists, check for the direnv configuration file.
|
||||||
|
if not test -f ".envrc"
|
||||||
|
echo 'eval "$(devenv direnvrc)"' > .envrc
|
||||||
|
direnv allow
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -f "devenv.nix"
|
||||||
|
emacsclient devenv.nix
|
||||||
|
else
|
||||||
|
echo -e "\e[31mCould not open devenv.nix as it was not created.\e[0m"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if test -f $HOME/.cargo/env.fish
|
if test -f $HOME/.cargo/env.fish
|
||||||
source "$HOME/.cargo/env.fish"
|
source "$HOME/.cargo/env.fish"
|
||||||
end
|
end
|
||||||
@@ -73,10 +107,8 @@ let tide_conf = builtins.readFile ./tide_config.fish; in
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
shellAliases = {
|
shellAliases = {
|
||||||
ec = "emacsclient -n --alternate-editor=emacs";
|
ec = "emacsclient -n --alternate-editor=\"emacs -nw\"";
|
||||||
pubip = "curl icanhazip.com";
|
pubip = "curl icanhazip.com";
|
||||||
redesktop = "kquitapp5 plasmashell && kstart5 plasmashell";
|
|
||||||
pulsefix = "pulseaudio --kill; pulseaudio --start";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user