profile-util 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. PATH="$HOME/usr/local/bin:$HOME/bin:$HOME/usr/bin:$PATH"
  2. export PATH
  3. export LC_ALL=en_US.UTF-8
  4. if [ -z "$BASEPATH" ]
  5. then
  6. export BASEPATH="$PATH"
  7. fi
  8. alias reset-path="export PATH=\"$BASEPATH\""
  9. detach() {
  10. for i; do [ -L "$i" ] && cp --remove-destination $(readlink "$i") "$i"; done
  11. }
  12. link-tools() {
  13. PATH=$HOME/tools/bin:$HOME/tools/usr/bin:$PATH
  14. LD_LIBRARY_PATH=$HOME/tools/lib:$HOME/tools/usr/lib:$LD_LIBRARY_PATH
  15. export PATH
  16. export LD_LIBRARY_PATH
  17. }
  18. unlink-tools() {
  19. PATH=$(echo $PATH | perl -pne "s/(?<=:)$HOME/tools.*://g")
  20. LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | perl -pne "s/(?<=:)$HOME/tools.*://g")
  21. export PATH
  22. export LD_LIBRARY_PATH
  23. }
  24. if [[ $(uname) == "Darwin" ]]
  25. then # OSX / FreeBSD
  26. alias list="ls -lFhG"
  27. else
  28. alias list="ls -lFh --color"
  29. fi
  30. alias listall="list -A"
  31. alias git-graph="git log --graph --pretty=oneline --abbrev-commit --decorate --all"
  32. alias disk-usage="ls -A | xargs du -shc | sort -h"
  33. alias reload="source ~/.profile-user"
  34. refreshterm() {
  35. clear
  36. uname -a
  37. cat /etc/motd
  38. echo ""
  39. pwd
  40. list
  41. }
  42. _mkcd_fun() {
  43. if [ ! -d "$2" ]; then
  44. if [ -e "$2" ]; then
  45. echo "mkcd: file exists and is not a directory"
  46. exit
  47. else
  48. $1 "$2"
  49. fi
  50. fi
  51. cd "$2"
  52. }
  53. alias mkcd="_mkcd_fun mkdir"
  54. mkdirs() {
  55. mkdir -p "$1"
  56. }
  57. alias mkcds="_mkcd_fun mkdirs_fun"
  58. alias diffr="diff --ignore-blank-lines --minimal --side-by-side --report-identical-files --suppress-common-lines"
  59. alias diffl="diff --changed-group-format='%<' --unchanged-group-format=''"
  60. _recall_fun() {
  61. if [ -z "$1" ]; then echo "recall: usage: recall string"; return 1; fi
  62. history | cut -c 8- | grep --extended-regexp "$1" | \
  63. grep --invert-match --extended-regexp "^(history|recall|redo)" | sort | uniq
  64. }
  65. redo() {
  66. IFS=$'\n'
  67. hist=($(_recall_fun $1))
  68. for ((i=0; i<${#hist[@]}; i++));
  69. do
  70. echo "[$i] ${hist[$i]}"
  71. done
  72. printf "Index: "
  73. read idx
  74. if [[ $idx =~ ^[0-9]+$ ]];
  75. then
  76. eval "${hist[$idx]}"
  77. fi
  78. unset IFS
  79. }
  80. recall(){
  81. _recall_fun $1 | sed 's/^/ /'
  82. }
  83. clear() {
  84. /usr/bin/clear
  85. if [[ ! -z "${TMUX}" ]]; then tmux clear-history; fi
  86. }
  87. swap() {
  88. if [[ $# -ne 2 ]]; then
  89. echo "swap file1 file2" >&2
  90. return 1
  91. fi
  92. local tmpfile=$(mktemp)
  93. mv "${1}" "${tmpfile}"
  94. mv "${2}" "${1}"
  95. mv "${tmpfile}" "${2}"
  96. }
  97. alias coms="${HOME}/tools/comstore/commands.sh"
  98. clrun() {
  99. clear
  100. echo "$@"
  101. "$@"
  102. }
  103. source ${HOME}/.profile-p4