Skip to content

Instantly share code, notes, and snippets.

@KSXGitHub
Created February 11, 2017 07:41
Show Gist options
  • Save KSXGitHub/445795a264248d55ce3f2eda0fb6dbbb to your computer and use it in GitHub Desktop.
Save KSXGitHub/445795a264248d55ce3f2eda0fb6dbbb to your computer and use it in GitHub Desktop.
Update GNOME Applications Menu
#! /usr/bin/env node
'use strict'
const {join} = require('path')
const {readdirSync} = require('fs')
const {env: {HOME}} = require('process')
const jtry = require('just-try')
const {ConcatIterable} = require('x-iterable')
const gsettingsArray = ([...array]) =>
'"[' + array.map(string => `'${String(string)}'`).join(', ') + ']"'
const addMsg = msg =>
output.push(`echo '\x1B[1m\x1B[33m${msg}\x1B[0m'`)
const addCmd = cmd =>
output.push(`echo '\x1B[1m\$\x1B[0m \x1B[94m${cmd}\x1B[0m'`, cmd)
const tryReadDir = dirname =>
jtry(() => readdirSync(dirname), () => [])
const folders = [
'Programming',
'Utilities',
'Sundry',
'Office',
'Network',
'Graphics',
'Media',
'Math',
'System',
'Games',
'Editor',
'Terminal',
'Recorder',
'Player',
'Video',
'Audio',
'Settings',
'Emulator',
'Core',
'GTK',
'Qt',
'Chrome',
'Android',
'Wine',
'NonNative',
'All'
]
const folderNames = {
Math: 'Mathematics',
GTK: 'GTK+ Apps',
Qt: 'Qt Apps',
Chrome: 'Chrome Apps',
Android: 'Android Apps',
Wine: 'Win32 Apps',
NonNative: 'Non-native Apps',
All: 'All Apps'
}
const folderCategoriesMap = {
Programming: ['Development', 'DevTools', 'Debug', 'Debugger', 'Compiler', 'IDE', 'Editor', 'Terminal', 'Console'],
Network: ['Internet', 'Browser', 'Web'],
Media: ['Player', 'Audio', 'Video', 'AudioVideo'],
Graphics: ['Paint', 'Photo', 'Image', '3D'],
Math: ['Mathematics', 'Algebra', 'Geometry', 'Spreadsheet', 'Calc', 'Calculator'],
Utilities: ['Utility', 'X-GNOME-Utility', 'X-GNOME-Utilities'],
Games: ['Game'],
Editor: ['TextEditor', 'IDE', 'GUIDesigner'],
Terminal: ['Console', 'TerminalEmulator'],
Debugger: ['Debug'],
Recorder: ['VideoRecorder', 'ScreenRecorder', 'AudioRecorder'],
Video: ['AudioVideo'],
Audio: ['AudioVideo', 'Sound'],
Settings: ['Configuration'],
Archiving: ['Compression', 'Archive', 'Compress'],
GTK: ['GNOME'],
Qt: ['KDE'],
Chrome: ['Chromium'],
Android: ['Shashlik'],
NonNative: ['Emulated', 'DOS', 'Web', 'Chrome', 'Android', 'Wine']
}
const foldersString = gsettingsArray(folders)
const output = []
addMsg('FOLDER CHILDREN')
addCmd(`gsettings set org.gnome.desktop.app-folders folder-children ${foldersString}`)
for (const folder of folders) {
addMsg(`CATEGORIES TO FOLDER: ${folder}`)
const name = folderNames[folder] || folder
addCmd(
`gsettings set org.gnome.desktop.app-folders.folder:/org/gnome/desktop/app-folders/folders/${folder}/ name '${name}'`
)
const categories = gsettingsArray([folder, ...folderCategoriesMap[folder] || []])
addCmd(
`gsettings set org.gnome.desktop.app-folders.folder:/org/gnome/desktop/app-folders/folders/${folder}/ categories ${categories}`
)
}
const appdirs = [
'/usr/share/applications',
join(HOME, '.local/share/applications'),
join(HOME, '.gnome/apps'),
join(HOME, '.local/share/flatpak/exports/share/applications')
]
const apps = new ConcatIterable(...appdirs.map(tryReadDir))
.filter(appName => /\.desktop$/.test(appName))
const chromeApps = apps
.filter(appName => /^chrome-/.test(appName))
const androidApps = apps
.filter(appName => /^(android|shashlik)-/.test(appName))
const wineApps = apps
.filter(appName => /^wine-/.test(appName))
const nonNativeApps = new ConcatIterable(chromeApps, androidApps, wineApps)
addMsg('APPS TO FOLDER: All')
addCmd(
`gsettings set org.gnome.desktop.app-folders.folder:/org/gnome/desktop/app-folders/folders/All/ apps ${gsettingsArray(apps)}`
)
addMsg('APPS TO FOLDER: Chrome')
addCmd(
`gsettings set org.gnome.desktop.app-folders.folder:/org/gnome/desktop/app-folders/folders/Chrome/ apps ${gsettingsArray(chromeApps)}`
)
addMsg('APPS TO FOLDER: Android')
addCmd(
`gsettings set org.gnome.desktop.app-folders.folder:/org/gnome/desktop/app-folders/folders/Android/ apps ${gsettingsArray(androidApps)}`
)
addMsg('APPS TO FOLDER: Wine')
addCmd(
`gsettings set org.gnome.desktop.app-folders.folder:/org/gnome/desktop/app-folders/folders/Wine/ apps ${gsettingsArray(wineApps)}`
)
addMsg('APPS TO FOLDER: NonNative')
addCmd(
`gsettings set org.gnome.desktop.app-folders.folder:/org/gnome/desktop/app-folders/folders/NonNative/ apps ${gsettingsArray(nonNativeApps)}`
)
const outputString = output.map(cmd => '(' + cmd + ') || exit $?').join('\n')
console.log(outputString)

Manual

Requirements

  • GNOME 3.22

  • Node.js v6.0.0 or later

Usage

View generated code

update-gnome-applications-menu | less # to view directly
update-gnome-applications-menu > to-a-file.sh # to save to a file

Organize GNOME apps menu

update-gnome-applications-menu | sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment