10 个开发人员的小助手脚本!
笔记
- 这是一些可以通过终端执行的小脚本的集合。
- 这些是为 Ubuntu(使用 zsh)设计的,但可能适用于其他 unixy 系统
- 有些是偷来的剧本,有些则是原创的!
- 脚本有多种语言,例如;
#!/usr/bin/env ruby
- 这些是集合的一部分
dotfiles
:- 它基本上是系统上用于组织个人脚本和终端配置的文件夹。
- 这是源代码仓库:https://github.com/benwinding/dotfiles
10 个小帮助脚本
(1)git-undo
#!/bin/sh
# Undo your last commit (in current folder), but don't throw away your changes
git reset --soft HEAD^
(2)gclonecd https://github.com/reactjs/react-modal
#!/bin/zsh
# Clones git repo and cd's into it
gclonecd() {
git_dir="$(basename "$1" .git)"
git_dir_resolved=${2:-$git_dir}
git clone "$@" && cd "$git_dir_resolved";
}
(3)killport 3000
#!/bin/zsh
# Kills a process running on a specified tcp port
killport() {
echo "Killing process on port: $1"
fuser -n tcp -k $1;
}
(4)mvp ./this-dir ./some/other/new/dir
#!/bin/zsh
# Move and make parents
function mvp () {
source="$1"
target="$2"
target_dir="$(dirname "$target")"
mkdir --parents $target_dir; mv $source $target
}
(5)dos2unixd ./dir
#!/bin/zsh
# Dos2unix a whole directory (crlf to lf)
dos2unixd() {
find $1 -type f -print0 | xargs -0 dos2unix
}
(6)docker-kill-all
# Kills all docker containers running
alias docker-kill-all='docker kill `docker ps -aq`'
(7)docker-rm-all
# Deletes all docker containers
alias docker-rm-all='docker rm `docker ps -aq`'
(8)git-delete-local-merged
#!/bin/bash
#
# Delete all local branches that have been merged into HEAD. Stolen from
# our favorite @tekkub:
#
# https://plus.google.com/115587336092124934674/posts/dXsagsvLakJ
branches=`git branch --merged master | grep -v '\*\|master\|unstable\|develop'`
[ -z "$branches" ] && printf '\nNo merged branches to delete...\n' && exit;
command="git branch -d $branches"
echo ''
printf '%s\n' "$branches"
echo ''
printf 'Delete merged branches locally? Press [Enter] to continue...'
read _
echo ''
echo 'Safely deleting merged local branches...'
echo 'Running command: '$command
`$command`
(9)git-delete-remote-merged
#!/bin/bash
remote='origin'
echo "Will delete the following branches from [$remote]:"
branches=`git branch -r --merged master | grep -v '\*\|master\|unstable\|develop'`
[ -z "$branches" ] && printf '\nNo merged branches to delete...\n' && exit;
echo ''
printf '%s\n' "$branches"
echo ''
printf 'Delete merged remote branches from '$remote'? Press [Enter] to continue'
read _
echo ''
echo 'Safely deleting merged remote branches...'
echo $branches | sed -e "s:$remote/::g" | xargs -t git push $remote -d
(10)github-open
#!/usr/bin/env ruby
# Opens the current github repository in the default browser
remotes = `git remote`
hasNoRemotes = remotes.size < 2
if hasNoRemotes then
return
end
repolink = `git remote get-url origin`
if repolink.include?("git@github.com:") then
# Converts from ssh format to https format if necessary
# git@github.com:benwinding/dotfiles
# https://github.com/benwinding/dotfiles
repolink = repolink.gsub("git@github.com:", "https://github.com/")
end
`xdg-open #{repolink}`
我强烈建议不熟悉 Shell 脚本的朋友们去看看Holman 的 dotfiles,它主要针对 make 用户。或者,我 fork 了Ben 的 dotfiles,它主要针对 Ubuntu 用户。
当您开始编写和维护自己的小型脚本和代码片段库时,您会对自己能够自动化和完成的工作感到惊讶。
文章来源:https://dev.to/benwinding/10-tiny-helper-scripts-for-devs-knb