Skip to content

Commit

Permalink
feat(fish): added autocomplition for programming projects commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Wittano committed Jan 27, 2024
1 parent 0116d66 commit a9dc090
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 62 deletions.
37 changes: 37 additions & 0 deletions lib/commands.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ lib, pkgs, home-manager, ... }: {
createProjectJumpCommand = path:
let
commandName = "p${builtins.baseNameOf path}";
command = pkgs.writeScriptBin "${commandName}" /*bash*/ ''
#!/usr/bin/env bash
if [ -n "$1" ]; then
cd "${path}/$1"
else
cd "${path}"
fi
'';
in
{
home-manager.users.wittano.programs.fish = {
interactiveShellInit = /*fish*/''
function get_projects_dir
ls ${path}
end
for project in (get_projects_dir)
complete -c ${commandName} -f -a "$project"
end
'';
functions.${commandName}.body = /*fish*/''
set -l args_len $(count $argv)
if test "$args_len" -eq 0
cd ${path}
else
cd ${path}/$argv
end
'';
};
};
}
4 changes: 3 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ let
dotfiles = mapper.mapDirToAttrs inputs.wittano-dotfiles;

home-manager = inputs.home-manager;
in {
in
{
inherit mapper imports;

hosts = import ./hosts.nix {
Expand All @@ -27,4 +28,5 @@ in {
apps = import ./apps.nix {
inherit lib home-manager pkgs dotfiles ownPackages unstable;
};
commands = import ./commands.nix { inherit pkgs lib home-manager; };
}
2 changes: 0 additions & 2 deletions modules/desktop/gaming/gaming.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ in
};

config = mkIf cfg.enable {
nix.settings = mkIf cfg.enableMihoyoGames inputs.aagl.nixConfig;

# Genshin Impact
programs.anime-game-launcher.enable = cfg.enableMihoyoGames;

Expand Down
36 changes: 17 additions & 19 deletions modules/dev/cpp.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{ config, lib, pkgs, ... }:
with lib;
let cfg = config.modules.dev.clion;
with lib.my;
let
cfg = config.modules.dev.clion;
pRustCommand = commands.createProjectJumpCommand "$HOME/projects/own/rust";
pCppCommand = commands.createProjectJumpCommand "$HOME/projects/own/cpp";
in
{
options = {
Expand All @@ -11,24 +15,18 @@ in
};
};

config = {
home-manager.users.wittano = {
home.packages = mkIf cfg.enable (with pkgs; [
cmake
gcc_multi
gnumake
glibc
config = mkIf cfg.enable (mkMerge [
pRustCommand
pCppCommand
{
home-manager.users.wittano = {
home.packages = (with pkgs; [
# Rust
rustup # TODO Split rust and cpp configuration

# Rust
rustup # TODO Split rust and cpp configuration

jetbrains.clion
]);

programs.fish.shellAliases = mkIf (config.modules.shell.fish.enable) {
pc = "cd $HOME/projects/own/cpp";
prust = "cd $HOME/projects/own/rust";
jetbrains.clion
]);
};
};
};
}
]);
}
22 changes: 11 additions & 11 deletions modules/dev/dotnet.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{ config, lib, pkgs, home-manger, ... }:
with lib;
let cfg = config.modules.dev.dotnet;
with lib.my;
let
cfg = config.modules.dev.dotnet;
pdotnetCommand = commands.createProjectJumpCommand "$HOME/projects/own/dotnet";
in
{
options = {
Expand All @@ -11,15 +14,12 @@ in
};
};

config = mkIf cfg.enable {
environment.variables.DOTNET_CLI_TELEMETRY_OPTOUT = "0";
config = mkIf cfg.enable (mkMerge [
pdotnetCommand
{
environment.variables.DOTNET_CLI_TELEMETRY_OPTOUT = "0";

home-manager.users.wittano = {
home.packages = with pkgs; [ dotnet-sdk mono jetbrains.rider ];

programs.fish.shellAliases = mkIf (config.modules.shell.fish.enable) {
pdotnet = "cd $HOME/projects/own/dotnet";
};
};
};
home-manager.users.wittano.home.packages = with pkgs; [ dotnet-sdk mono jetbrains.rider ];
}
]);
}
22 changes: 12 additions & 10 deletions modules/dev/go.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{ config, pkgs, lib, home-manager, ... }:
with lib;
let cfg = config.modules.dev.goland;
with lib.my;
let
cfg = config.modules.dev.goland;
pgoCommand = commands.createProjectJumpCommand "$HOME/projects/own/go";
in
{
options = {
Expand All @@ -11,15 +14,14 @@ in
};
};

config = {
home-manager.users.wittano = {
home.packages = mkIf cfg.enable (with pkgs; [ jetbrains.goland ]);
programs.fish.shellAliases = mkIf (config.modules.shell.fish.enable) {
pgo = "cd $HOME/projects/own/go";
tempgo =
config = mkIf (cfg.enable) (mkMerge [
pgoCommand
{
home-manager.users.wittano = {
home.packages = mkIf cfg.enable (with pkgs; [ jetbrains.goland ]);
programs.fish.shellAliases.tempgo =
"${pkgs.nixFlakes}/bin/nix flake init --template github:Wittano/nix-template#go";
};
};
};

}
]);
}
18 changes: 9 additions & 9 deletions modules/dev/jvm.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{ config, pkgs, lib, home-manager, ... }:
with lib;
with lib.my;
let
cfg = config.modules.dev.jvm;
andoridStudio = lists.optionals cfg.enableAndroid [ andorid-studio ];
pjvmCommand = commands.createProjectJumpCommand "$HOME/projects/own/jvm";
in
{
options = {
Expand All @@ -16,13 +18,11 @@ in
};
};

config = mkIf cfg.enable {
home-manager.users.wittano = {
home.packages = with pkgs; [ jetbrains.idea-ultimate ] ++ andoridStudio;

programs.fish.shellAliases = mkIf (config.modules.shell.fish.enable) {
pjvm = "cd $HOME/projects/own/jvm";
};
};
};
config = mkIf cfg.enable
(mkMerge [
pjvmCommand
{
home-manager.users.wittano.home.packages = with pkgs; [ jetbrains.idea-ultimate ] ++ andoridStudio;
}
]);
}
22 changes: 12 additions & 10 deletions modules/dev/python.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{ config, pkgs, lib, home-manager, ... }:
with lib;
let cfg = config.modules.dev.pycharm;
with lib.my;
let
cfg = config.modules.dev.pycharm;
ppythonCommand = commands.createProjectJumpCommand "$HOME/projects/own/python";
in
{
options = {
Expand All @@ -11,16 +14,15 @@ in
};
};

config = {
home-manager.users.wittano = {
home.packages = mkIf cfg.enable
(with pkgs; [ python3 pipenv poetry jetbrains.pycharm-professional ]);
config = mkIf (cfg.enable) (mkMerge [
ppythonCommand
{
home-manager.users.wittano = {
home.packages = with pkgs; [ python3 pipenv poetry jetbrains.pycharm-professional ];

programs.fish.shellAliases = mkIf (config.modules.shell.fish.enable) {
ppython = "cd $HOME/projects/own/python";
temppy =
programs.fish.shellAliases.temppy =
"${pkgs.nixFlakes}/bin/nix flake init --template github:nix-community/poetry2nix";
};
};
};
}
]);
}

0 comments on commit a9dc090

Please sign in to comment.