File indexing completed on 2024-04-28 05:13:31

0001 #!/bin/sh
0002 
0003 KDEDIR=$(grep kdedir $XDG_CONFIG_HOME/kdesrc-buildrc  | awk '{ print $2 }')
0004 
0005 export KDE_BUILD=$(grep build-dir $XDG_CONFIG_HOME/kdesrc-buildrc  | awk '{ print $2 }')
0006 export KDE_SRC=$(grep source-dir $XDG_CONFIG_HOME/kdesrc-buildrc  | awk '{ print $2 }')
0007 
0008 ##
0009 # A function to easily change to the build directory.
0010 # Usage: cb KDE/kdebase
0011 #   will change to $KDE_BUILD/KDE/kdebase
0012 # Usage: cb
0013 #   will simply go to the build folder if you are currently in a src folder
0014 #   Example:
0015 #     $ pwd
0016 #     /home/user/src/KDE/kdebase
0017 #     $ cb && pwd
0018 #     /home/user/build/KDE/kdebase
0019 #
0020 function cb {
0021         local dest
0022 
0023     # Make sure build directory exists.
0024     mkdir -p "$KDE_BUILD"
0025 
0026     # command line argument
0027     if test -n "$1"; then
0028         cd "$KDE_BUILD/$1"
0029         return
0030     fi
0031     # substitute src dir with build dir
0032     dest=`pwd | sed -e s,$KDE_SRC,$KDE_BUILD,`
0033     if test ! -d "$dest"; then
0034         # build directory does not exist, create
0035         mkdir -p "$dest"
0036     fi
0037     cd "$dest"
0038 }
0039 
0040 ##
0041 # Change to the source directory.  Same as cb, except this
0042 # switches to $KDE_SRC instead of $KDE_BUILD.
0043 # Usage: cs KDE/kdebase
0044 #   will change to $KDE_SRC/KDE/kdebase
0045 # Usage: cs
0046 #   will simply go to the source folder if you are currently in a build folder
0047 #   Example:
0048 #     $ pwd
0049 #     /home/myuser/kde/build/master/KDE/kdebase
0050 #     $ cs && pwd
0051 #     /home/myuser/kde/src/master/KDE/kdebase
0052 #
0053 function cs {
0054         local dest current
0055 
0056     # Make sure source directory exists.
0057     mkdir -p "$KDE_SRC"
0058 
0059     # command line argument
0060     if test -n "$1"; then
0061         cd "$KDE_SRC/$1"
0062     else
0063         # substitute build dir with src dir
0064         dest=`pwd | sed -e s,$KDE_BUILD,$KDE_SRC,`
0065         current=`pwd`
0066         if [ "$dest" = "$current" ]; then
0067             cd "$KDE_SRC"
0068         else
0069             cd "$dest"
0070         fi
0071     fi
0072 }
0073 
0074 ##
0075 # Add autocompletion to cs function
0076 #
0077 function _cs_scandir
0078 {
0079         local base ext
0080 
0081     base=$1
0082     ext=$2
0083     if [ -d $base ]; then
0084         for d in `ls $base`; do
0085             if [ -d $base/$d ]; then
0086                 dirs="$dirs $ext$d/"
0087             fi
0088         done
0089     fi
0090 }
0091 
0092 function _cs()
0093 {
0094     local cur dirs
0095     _cs_scandir "$KDE_SRC"
0096     _cs_scandir "$KDE_SRC/KDE" "KDE/"
0097     _cs_scandir "$KDE_SRC/kde" "kde/"
0098     _cs_scandir "$KDE_SRC/kde/pim" "kde/pim/"
0099     _cs_scandir "$KDE_SRC/frameworks" "frameworks/"
0100     COMPREPLY=()
0101     cur="${COMP_WORDS[COMP_CWORD]}"
0102     COMPREPLY=( $(compgen -W "${dirs}" -- ${cur}) )
0103 }
0104 
0105 # Setup shell
0106 complete -F _cs cs
0107 complete -F _cs cb
0108