Skip to content

Commit

Permalink
Add shortcut command to move into Windows folders in WSL2
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Aug 30, 2024
1 parent 0c02185 commit 0f07b6c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 40 deletions.
69 changes: 29 additions & 40 deletions pkgs/posix_shared_functions/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,36 @@ let
pkgs.callPackage ../fzf-bind-posix-shell-history-to-git-commit-message
{ };
in
pkgs.writeText "posix_shared_functions.sh" ''
cdg() {
local -r query_repoonly="$(echo "$1" | ${lib.getExe trim-github-user-prefix-for-reponame})"
local -r repo="$(${lib.getExe ghqf} "$query_repoonly")"
if [ -n "$repo" ]; then
cd "$(${lib.getExe pkgs.ghq} list --full-path --exact "$repo")"
fi
}
pkgs.writeText "posix_shared_functions.sh" (
''
cdrepo() {
local -r query_repoonly="$(echo "$1" | ${lib.getExe trim-github-user-prefix-for-reponame})"
local -r repo="$(${lib.getExe ghqf} "$query_repoonly")"
if [ -n "$repo" ]; then
cd "$(${lib.getExe pkgs.ghq} list --full-path --exact "$repo")"
fi
}
gg() {
${lib.getExe pkgs.ghq} get "$1" && cdg "$1"
}
getrepo() {
${lib.getExe pkgs.ghq} get "$1" && cdrepo "$1"
}
cdt() {
cd "$(${pkgs.coreutils}/bin/mktemp --directory)"
}
cdtemp() {
cd "$(${pkgs.coreutils}/bin/mktemp --directory)"
}
cdn() {
if [ $# -lt 1 ]; then
echo "Specify Nix injected command you want to dive"
return 2
fi
# TODO: Check exit code and Nix or not
local -r command="$(command -v "$1")"
cd "$(dirname "$(dirname "$(readlink "$command")")")"
}
gch() {
fc -nrl 1 | ${lib.getExe fzf-bind-posix-shell-history-to-git-commit-message}
}
gch() {
fc -nrl 1 | ${lib.getExe fzf-bind-posix-shell-history-to-git-commit-message}
}
disable_blinking_cursor() {
echo -en '\033[?16;5;140c'
}
yy() {
local tmp="$(${pkgs.coreutils}/bin/mktemp -t "yazi-cwd.XXXXXX")"
${lib.getExe pkgs.yazi} "$@" --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
builtin cd -- "$cwd"
fi
${pkgs.coreutils}/bin/rm -f -- "$tmp"
}
''
yy() {
local tmp="$(${pkgs.coreutils}/bin/mktemp -t "yazi-cwd.XXXXXX")"
${lib.getExe pkgs.yazi} "$@" --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
builtin cd -- "$cwd"
fi
${pkgs.coreutils}/bin/rm -f -- "$tmp"
}
''
+ (builtins.readFile ./non_nix.bash)
)
23 changes: 23 additions & 0 deletions pkgs/posix_shared_functions/non_nix.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cdnix() {
if [ $# -lt 1 ]; then
echo "Specify Nix injected command you want to dive"
return 2
fi
# TODO: Check exit code and Nix or not
local -r command="$(command -v "$1")"
# shellcheck disable=SC2164
cd "$(dirname "$(dirname "$(readlink "$command")")")"
}

cdwin() {
if ! command -v wslpath &>/dev/null; then
echo "This command works only in WSL2"
fi

# shellcheck disable=SC2164
cd "$(wslpath "$1")"
}

disable_blinking_cursor() {
echo -en '\033[?16;5;140c'
}

0 comments on commit 0f07b6c

Please sign in to comment.