~skiqqy/.dotfiles

ref: 907855e89d59b585c6ee169ba0be45df6a2a6691 .dotfiles/miscfiles/atom/atom.sh -rw-r--r-- 2.1 KiB
907855e8Stephen Cochrane Other changes 6 months ago
                                                                                
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash

ROOT=$(realpath "${BASH_SOURCE/atom.sh/}/../../") # Find the root of the project
! command -v atom > /dev/null && exit

# Add names of packages to install here
# use sync to get packages not included in this list
packages()
{
    cat << EOF | sort
atom-ide-ui
ide-java
autocomplete-java
vim-modeline
vim-mode-plus
java-import-wiz
busy
gruvbox
nord-atom-ui
project-manager
iv-terminal
EOF
}

add()
{
    ! command -v apm && return
    rm -rf "$HOME/.backup/.atom"
    mv "$HOME/.atom/" "$HOME/.backup/.atom" 2> /dev/null
    mkdir -p "$HOME/.atom"
    touch "$HOME/.backup/.dfATOM"

    mapfile -t packages < <(packages)

    apm install ${packages[*]} # i want splitting

    for cfg in "$ROOT/miscfiles/atom"/*.cson
    do
        ln -s "$cfg" "$HOME/.atom/$(basename "$cfg")"
    done
}

remove()
{
    if [ -f "$HOME/.backup/.dfATOM" ]
    then
        rm -rf "$HOME/.atom"
        mv "$HOME/.backup/.atom" "$HOME/.atom"
        rm "$HOME/.dfATOM"
    else
        return
    fi
}

# Prints 'missing' packages
diff()
{
    grep -f <(packages) -vFx <(
    while read -r package
    do
        basename "$package"
    done < <(find "$HOME/.atom/packages" -maxdepth 1 -type d | tail -n +2) | sort
    )
}

# Used to install missing packeges
sync()
{
    while read -r missing
    do
        apm install "$missing"
    done < <(comm -3 <(packages) <(
        while read -r package
        do
            basename "$package"
        done < <(find "$HOME/.atom/packages" -maxdepth 1 -type d | tail -n +2) | sort
    ))
    echo "Sync completed."
}

main()
{
    case "$1" in
        install|i)
            add
            ;;
        remove|rm)
            remove
            ;;
        diff) # Prints the packages that are missing from packages()
            diff 
            diff | xclip -r -selection clipboard
            echo "Diff placed in clipboard..."
            ;;
        sync) # updates an existing installation
            sync
            ;;
        ''|-h|--help|help)
            printf "\n Usage:\n\n   $ bash %s install|remove|sync\n\n" "$0"
            ;;
        *)
            echo "Unknown cmd: $1"
            exit 1
            ;;
    esac
}

main "$@"