将 git stash poop 别名设为 pop?

30

这个问题可能有些愚蠢,但我真的不确定是否可行。

我经常打错 "git stash pop" (不用管为什么)。 我能否将我的错误映射/快捷方式/别名到正确的命令上?


15
今天我拼错了这个词,我在想如果我搜索“git stash poop”会找到什么。 - Emanuel
1
然后你会发现这个:https://github.com/markhobson/git-stash-poop - Borislav Ivanov
3
9年后,这是我对Stack Overflow最大的贡献。我感到非常自豪! - jgillman
3个回答

18
git config --global alias.sp 'stash pop'

那么git sp会被扩展为git stash pop


17

定义一个Shell函数:

git() {
  if [ "$1" == "stash" -a "$2" == "poop" ]; then
    shift; shift; command git stash pop "$@"
  else
    command git "$@"
  fi
}

1
从技术上讲,这是正确的答案,但我认为使用别名来避免问题是更好的全局解决方案。 - jgillman

15

如果您需要正确生成的输出...

if [ "$1" == "stash" -a "$2" == "poop" ]
  then
      command git stash pop
      echo "
   )  )
  (   ) (
   ) _   )
    ( \_
  _(_\ \)__
 (____\___))"
  else
      command git "$@"
  fi;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接