profile-util 2.5 KB

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