aboutsummaryrefslogtreecommitdiff
path: root/vim/.bash/vim.bash
blob: 7141113cacdbf2eae4dd2b936b04180d88821e71 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Vim specific config options imported by .bashrc

# Use this folder to store session files
export VIM_SESSIONS=$HOME/.local/share/vim/sessions

# Open Vim loading the appropriate project session based on the name of
# the current folder. If it does not exists create a new one.
vims() {
    mkdir -p "$VIM_SESSIONS"
    if [ -d "$VIM_SESSIONS" ];
    then
        # Computes the current folder name (possibly the name of the
        # project).
        local folder="${PWD##*/}"
        # Removes any dots in front of the folder name.
        local session="$VIM_SESSIONS/${folder#.}.vim"
        if [ -f $session ];
        then
            # If a session file exists, use it.
            vim -S "$session"
        else
            # Otherwise open vim and start a new session.
            vim +"call dyamon#session#new(\"$session\")"
        fi
    else
        exit 1
    fi
}