Skip to content

Commit

Permalink
feat: add snap defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
yasinmiran committed Jan 29, 2024
1 parent 1f79f56 commit d42e9eb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
49 changes: 49 additions & 0 deletions snap/defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env zsh

export SNAPLIST_FILE="$DOTFILES_DIR/snap/Snaplist"

function dump_snap_dependencies() {
# Check if snap command is available
if ! command -v snap &>/dev/null; then
echo "Snap is not installed. Exiting."
return 1
fi
# Dump installed snaps to Snaplist excluding 'snapd'
snap list | awk '{if(NR>1 && $1 != "snapd") print $1}' >"$SNAPLIST_FILE"
# Check if the file was created and has content
if [ -s "$SNAPLIST_FILE" ]; then
echo "Snap dependencies have been dumped to $SNAPLIST_FILE."
else
echo "Failed to dump Snap dependencies or no snaps are installed."
return 1
fi
}

function is_snap_installed() {
if command -v snap >/dev/null; then
return 0 # Snap is installed
else
return 1 # Snap is not installed
fi
}

function install_snaps_from_list() {
# Check if the Snaplist file exists
if [ ! -f "$SNAPLIST_FILE" ]; then
echo "$SNAPLIST_FILE does not exist. Please make sure the file is in the current directory."
return 1
fi
# Check if snap command is available
if ! command -v snap &>/dev/null; then
echo "Snap is not installed. Please install snapd first."
return 1
fi
# Read from the Snaplist file and install each snap
while IFS= read -r snap; do
if [ -n "$snap" ]; then # Check if the line is not empty
echo "Installing $snap..."
sudo snap install "$snap"
fi
done <"$SNAPLIST_FILE"
echo "All snaps from $SNAPLIST_FILE have been processed."
}
48 changes: 1 addition & 47 deletions snap/setup_snap
Original file line number Diff line number Diff line change
@@ -1,52 +1,6 @@
#!/usr/bin/env zsh

export SNAPLIST_FILE="$DOTFILES_DIR/snap/Snaplist"

function dump_snap_dependencies() {
# Check if snap command is available
if ! command -v snap &>/dev/null; then
echo "Snap is not installed. Exiting."
return 1
fi
# Dump installed snaps to Snaplist excluding 'snapd'
snap list | awk '{if(NR>1 && $1 != "snapd") print $1}' >"$SNAPLIST_FILE"
# Check if the file was created and has content
if [ -s "$SNAPLIST_FILE" ]; then
echo "Snap dependencies have been dumped to $SNAPLIST_FILE."
else
echo "Failed to dump Snap dependencies or no snaps are installed."
return 1
fi
}

function is_snap_installed() {
if command -v snap >/dev/null; then
return 0 # Snap is installed
else
return 1 # Snap is not installed
fi
}

function install_snaps_from_list() {
# Check if the Snaplist file exists
if [ ! -f "$SNAPLIST_FILE" ]; then
echo "$SNAPLIST_FILE does not exist. Please make sure the file is in the current directory."
return 1
fi
# Check if snap command is available
if ! command -v snap &>/dev/null; then
echo "Snap is not installed. Please install snapd first."
return 1
fi
# Read from the Snaplist file and install each snap
while IFS= read -r snap; do
if [ -n "$snap" ]; then # Check if the line is not empty
echo "Installing $snap..."
sudo snap install "$snap"
fi
done <"$SNAPLIST_FILE"
echo "All snaps from $SNAPLIST_FILE have been processed."
}
source "$DOTFILES_DIR/snap/defaults"

# Main script starts here
if is_snap_installed; then
Expand Down
6 changes: 4 additions & 2 deletions zsh/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function darwin() {
alias get="brew install"
alias j2="jinja2"

. "$DOTFILES_DIR/brew/defaults"
source "$DOTFILES_DIR/brew/defaults"

alias stfu='osascript -e "set volume output volume 0"'
alias vv='osascript -e "set volume output volume 50"'
Expand All @@ -209,6 +209,8 @@ function linux() {

echo "Applying your Linux specific configs..."

source "$DOTFILES_DIR/snap/defaults"

}

function common() {
Expand All @@ -220,7 +222,7 @@ function common() {
export -f ls
fi

. "$DOTFILES_DIR/git/defaults"
source "$DOTFILES_DIR/git/defaults"

alias dlistall="docker ps -a"
alias dstart="docker start"
Expand Down

0 comments on commit d42e9eb

Please sign in to comment.