git_claw/workflow/
shell.rs1use crate::workflow::error::WorkflowError;
7
8pub struct ShellHookOptions<'a> {
10 pub shell: &'a str,
11}
12
13pub fn generate_shell_hook(_shell: &str) -> String {
25 r#"# git-claw shell integration for bash and zsh
26# Usage: eval "$(git claw shell-hook)" or eval "$(git-claw shell-hook)"
27
28claw() {
29 if [ "$1" = "cd" ]; then
30 local dest
31 dest="$(command git-claw cd "$2")" || return $?
32 if [ -n "$dest" ]; then
33 cd "$dest" || return $?
34 fi
35 elif [ "$2" = "start" ] && { [ "$1" = "feature" ] || [ "$1" = "bugfix" ] || [ "$1" = "hotfix" ] || [ "$1" = "spike" ]; }; then
36 local target_name="$3"
37 for arg in "$@"; do
38 case "$arg" in
39 feature|bugfix|hotfix|spike|start|--*) ;;
40 *) target_name="$arg"; break ;;
41 esac
42 done
43 command git-claw "$@" || return $?
44 if [ -n "$target_name" ]; then
45 local dest
46 dest="$(command git-claw cd "$target_name")" || return $?
47 if [ -n "$dest" ]; then
48 cd "$dest" || return $?
49 fi
50 fi
51 else
52 command git-claw "$@"
53 fi
54}
55
56git() {
57 if [ "$1" = "claw" ]; then
58 shift
59 claw "$@"
60 else
61 command git "$@"
62 fi
63}
64"#
65 .to_string()
66}
67
68pub fn run_shell_hook(options: ShellHookOptions) -> Result<(), WorkflowError> {
79 let script = generate_shell_hook(options.shell);
80 print!("{}", script);
81 Ok(())
82}